﻿using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Charts;
using FlyHorse.LIMS.Model;
using FlyHorse.LIMS.WinApp.Utils;
using FlyHorse.LIMS.WinApp.Utils.MonthReportUtils.MonthReportModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using FlyHorse.LIMS.WinApp.LanguageResource;

namespace FlyHorse.LIMS.WinApp.DataAnalyzeFroms.MonthlyReport
{
    public partial class MonthReportForm : Form
    {
        OJCB4Entities db = new OJCB4Entities();
        public MonthReportForm()
        {
            InitializeComponent();
        }

        private void MonthReportForm_Load(object sender, EventArgs e)
        {

        }
        private void barButtonItem_Submit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            if (barEditItem_StartData.EditValue == null || barEditItem_EndDate.EditValue == null)
            {
                XtraMessageBox.Show(ResourceOverall.InputNull);
                return;
            }

            //DateTime startDate = new DateTime(2017, 06, 01);
            //DateTime endDate = new DateTime(2017, 06, 30, 23, 59, 59);

            spreadsheetControl1.BeginUpdate();

            DateTime startDate = Convert.ToDateTime(this.barEditItem_StartData.EditValue);
            DateTime endDate = Convert.ToDateTime(this.barEditItem_EndDate.EditValue);
            endDate = endDate.AddHours(23).AddMinutes(59).AddSeconds(59);

            //0  初始化所有的Sheet
            InitialAllSheet();

            //1原材料报告
            splashScreenManager1.ShowWaitForm();
            splashScreenManager1.SetWaitFormCaption(ResourceOverall.CreatingRawReport);   //creating report of raw material 
            RawReport(startDate, endDate);
            splashScreenManager1.CloseWaitForm();
            //2DO报告
            splashScreenManager1.ShowWaitForm();
            splashScreenManager1.SetWaitFormCaption(ResourceOverall.CreatingDOreport);      //  creating  report of   DO  
            DoReport(startDate, endDate);
            splashScreenManager1.CloseWaitForm();
            ////3合成样品报告
            splashScreenManager1.ShowWaitForm();
            splashScreenManager1.SetWaitFormCaption(ResourceOverall.CreatingCompReport);     //    creating    report of Comp  
            CompReport(startDate, endDate);
            splashScreenManager1.CloseWaitForm();

            ////4包装复检产品罐取样
            splashScreenManager1.ShowWaitForm();
            splashScreenManager1.SetWaitFormCaption(ResourceOverall.CreatingPackingReport);  //  creating  report of Packing        3)
            PackingReport(startDate, endDate);
            splashScreenManager1.CloseWaitForm();


            //////5 出厂报告
            splashScreenManager1.ShowWaitForm();
            splashScreenManager1.SetWaitFormCaption(ResourceOverall.CreatingShippingReport);   //  creating  report of  Shipping       3)
            ShippingReport(startDate, endDate);
            splashScreenManager1.CloseWaitForm();


            //删除sheet1
            IWorkbook workbook = spreadsheetControl1.Document;

            workbook.Worksheets.Remove(workbook.Worksheets["Sheet1"]);
            workbook.Worksheets.ActiveWorksheet = workbook.Worksheets["1)RawMaterial"];

            spreadsheetControl1.EndUpdate();

        }


        private void InitialAllSheet()
        {
            spreadsheetControl1.CreateNewDocument();
            IWorkbook workbook = spreadsheetControl1.Document;
            //for (int i = 1; i < workbook.Worksheets.Count; i++)
            //{
            //    workbook.Worksheets.RemoveAt(i);
            //}

            workbook.Worksheets.Add("1)RawMaterial");
            workbook.Worksheets.Add("2)DO");
            workbook.Worksheets.Add("2)Comp");
            workbook.Worksheets.Add("3)Packing");
            workbook.Worksheets.Add("4)Shipping");
            //workbook.Worksheets.Add("5)Complaint");
            workbook.Worksheets.Add("DO_ThisMonthData");
            workbook.Worksheets.Add("DO_ThisYearData");
            workbook.Worksheets.Add("Comp_ThisMonthData");
            workbook.Worksheets.Add("Comp_ThisYearData");
            workbook.Worksheets.Add("Packing_ThisMonthData");
            workbook.Worksheets.Add("Packing_ThisYearData");
            workbook.Worksheets.Add("Shipping_ThisMonthData");
            workbook.Worksheets.Add("Shipping_ThisYearData");

        }

        private void RawReport(DateTime startDate, DateTime endDate)
        {
            //1：创建  包含dataTable 的 LIst
            CreateDataSourceRaw(startDate, endDate);
            DecorateRawReport(startDate, endDate);
        }
        private void DoReport(DateTime startDate, DateTime endDate)
        {
            InitDoReport(startDate, endDate);
        }
        private void CompReport(DateTime startDate, DateTime endDate)   //合成样品
        {
            InitialCompReport(startDate, endDate);
        }
        private void PackingReport(DateTime startDate, DateTime endDate)  //包装复检
        {
            InitPackingReport(startDate, endDate);
        }
        private void ShippingReport(DateTime startDate, DateTime endDate)    //出厂报告
        {
            InitialShippingReport(startDate, endDate);
        }

        //////////////////////////////////////////////华丽的分割线////////////////////////////////////////////////////////////

        #region 原材料报告相关方法
        private void CreateDataSourceRaw(DateTime startDate, DateTime endDate)
        {
            int rowIndex = 1;
            int rowIndexRawAllData = 1;
            int rowsWhitoutData = 10;
            List<RawMaterialMonthReportModel> sourceList = new List<RawMaterialMonthReportModel>();
            List<RawMaterialMonthReportModel> sourceListYear = new List<RawMaterialMonthReportModel>();
            //创建goodsLIst
            List<Good> rawGoodsList = (from m in db.Goods where m.GoodsTypeID == CommonData.GoodsType_Raw_ID select m).ToList();
            foreach (var item in rawGoodsList)
            {
                RawMaterialMonthReportModel rawModel = new RawMaterialMonthReportModel();
                rawModel.startRowIndex = rowIndex;
                rawModel.goodsName = item.GoodsName;
                rawModel.standardRawList = db.StandardRaws.Where(m => m.GoodsID == item.GoodsID).ToList();

                //string sql1 = "SELECT [Project9].[SendDate] AS [AnalysisDate], [Project9].[ProductionUnit] AS [ProductionUnit], CONVERT(float,[Project9].[TestValue]) AS [SP/Gr], CONVERT(float,[Project9].[TestValue1]) AS [Mositure], CONVERT(float,[Project9].[TestValue2]) AS [BMCI], CONVERT(float,[Project9].[TestValue3]) AS [Englar Viscosity] FROM ( SELECT [Project7].[ProductionUnit] AS [ProductionUnit], [Project7].[SendDate] AS [SendDate], [Project7].[TestValue] AS [TestValue], [Project7].[TestValue1] AS [TestValue1], [Project7].[TestValue2] AS [TestValue2], [Limit4].[TestValue] AS [TestValue3], 1 AS [C1] FROM (SELECT [Project5].[ReportRawID] AS [ReportRawID], [Project5].[ProductionUnit] AS [ProductionUnit], [Project5].[SendDate] AS [SendDate], [Project5].[TestValue] AS [TestValue], [Project5].[TestValue1] AS [TestValue1], [Limit3].[TestValue] AS [TestValue2] FROM (SELECT [Project3].[ReportRawID] AS [ReportRawID], [Project3].[ProductionUnit] AS [ProductionUnit], [Project3].[SendDate] AS [SendDate], [Project3].[TestValue] AS [TestValue], [Limit2].[TestValue] AS [TestValue1] FROM (SELECT [Project1].[ReportRawID] AS [ReportRawID], [Project1].[ProductionUnit] AS [ProductionUnit], [Project1].[SendDate] AS [SendDate], [Limit1].[TestValue] AS [TestValue] FROM (SELECT [Extent1].[ReportRawID] AS [ReportRawID], [Extent1].[ProductionUnit] AS [ProductionUnit], [Extent1].[SendDate] AS [SendDate] FROM [dbo].[ReportRaws] AS [Extent1] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ([Extent1].[SendDate] >= @StartDate ) AND ([Extent1].[SendDate] <= @EndDate) ) AS [Project1] OUTER APPLY (SELECT TOP (1) [Extent2].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent2] WHERE ([Project1].[ReportRawID] = [Extent2].[ReportRawID]) AND ('48' = [Extent2].[TestItemID]) ) AS [Limit1] ) AS [Project3] OUTER APPLY (SELECT TOP (1) [Extent3].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent3] WHERE ([Project3].[ReportRawID] = [Extent3].[ReportRawID]) AND ('49' = [Extent3].[TestItemID]) ) AS [Limit2] ) AS [Project5] OUTER APPLY (SELECT TOP (1) [Extent4].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent4] WHERE ([Project5].[ReportRawID] = [Extent4].[ReportRawID]) AND ('54' = [Extent4].[TestItemID]) ) AS [Limit3] ) AS [Project7] OUTER APPLY (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent5] WHERE ([Project7].[ReportRawID] = [Extent5].[ReportRawID]) AND ('61' = [Extent5].[TestItemID]) ) AS [Limit4] ) AS [Project9] ORDER BY [Project9].[SendDate] ASC";
                string sql = "SELECT [Project9].[SendDate] AS [AnalysisDate], [Project9].[ProductionUnit] AS [ProductionUnit], CASE [Project9].[TestValue] WHEN '' THEN NUll ELSE CONVERT(float,[Project9].[TestValue]) END AS [SP/Gr], CASE [Project9].[TestValue1] WHEN '' THEN NUll ELSE CONVERT(float,[Project9].[TestValue1]) END AS [Mositure], CASE [Project9].[TestValue2] WHEN '' THEN NUll ELSE CONVERT(float,[Project9].[TestValue2]) END AS [BMCI], CASE [Project9].[TestValue3] WHEN '' THEN NUll ELSE CONVERT(float,[Project9].[TestValue3]) END AS [Englar Viscosity] FROM ( SELECT [Project7].[ProductionUnit] AS [ProductionUnit], [Project7].[SendDate] AS [SendDate], [Project7].[TestValue] AS [TestValue], [Project7].[TestValue1] AS [TestValue1], [Project7].[TestValue2] AS [TestValue2], [Limit4].[TestValue] AS [TestValue3], 1 AS [C1] FROM (SELECT [Project5].[ReportRawID] AS [ReportRawID], [Project5].[ProductionUnit] AS [ProductionUnit], [Project5].[SendDate] AS [SendDate], [Project5].[TestValue] AS [TestValue], [Project5].[TestValue1] AS [TestValue1], [Limit3].[TestValue] AS [TestValue2] FROM (SELECT [Project3].[ReportRawID] AS [ReportRawID], [Project3].[ProductionUnit] AS [ProductionUnit], [Project3].[SendDate] AS [SendDate], [Project3].[TestValue] AS [TestValue], [Limit2].[TestValue] AS [TestValue1] FROM (SELECT [Project1].[ReportRawID] AS [ReportRawID], [Project1].[ProductionUnit] AS [ProductionUnit], [Project1].[SendDate] AS [SendDate], [Limit1].[TestValue] AS [TestValue] FROM (SELECT [Extent1].[ReportRawID] AS [ReportRawID], [Extent1].[ProductionUnit] AS [ProductionUnit], [Extent1].[SendDate] AS [SendDate] FROM [dbo].[ReportRaws] AS [Extent1] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ([Extent1].[SendDate] >= @StartDate ) AND ([Extent1].[SendDate] <= @EndDate) ) AS [Project1] OUTER APPLY (SELECT TOP (1) [Extent2].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent2] WHERE ([Project1].[ReportRawID] = [Extent2].[ReportRawID]) AND ('48' = [Extent2].[TestItemID]) ) AS [Limit1] ) AS [Project3] OUTER APPLY (SELECT TOP (1) [Extent3].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent3] WHERE ([Project3].[ReportRawID] = [Extent3].[ReportRawID]) AND ('49' = [Extent3].[TestItemID]) ) AS [Limit2] ) AS [Project5] OUTER APPLY (SELECT TOP (1) [Extent4].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent4] WHERE ([Project5].[ReportRawID] = [Extent4].[ReportRawID]) AND ('54' = [Extent4].[TestItemID]) ) AS [Limit3] ) AS [Project7] OUTER APPLY (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportRawResults] AS [Extent5] WHERE ([Project7].[ReportRawID] = [Extent5].[ReportRawID]) AND ('61' = [Extent5].[TestItemID]) ) AS [Limit4] ) AS [Project9] ORDER BY [Project9].[SendDate] ASC";

                SqlParameter startDateSqlParameter = new SqlParameter("@StartDate", startDate);
                SqlParameter endDateSqlParameter = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameter = new SqlParameter("@GoodsID", item.GoodsID);
                SqlParameter[] SqlParameters = new SqlParameter[] { startDateSqlParameter, endDateSqlParameter, GoodsIDSqlParameter };
                rawModel.dataTable = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParameters);

                rawModel.endRowIndex = rowIndex + rawModel.dataTable.Rows.Count + rowsWhitoutData;
                if (rawModel.dataTable.Rows.Count > 0)
                {
                    sourceList.Add(rawModel);
                    rowIndex = rowIndex + rawModel.dataTable.Rows.Count + rowsWhitoutData + 2;
                }

            }
            //2  开始遍历List  绑定DataTable 到excel
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetRawMaterial = workbook.Worksheets["1)RawMaterial"];

            for (int i = 0; i < sourceList.Count; i++)
            {
                //写原材料名称
                worksheetRawMaterial[sourceList[i].startRowIndex, 1].Value = (i + 1) + ")" + sourceList[i].goodsName;

                //绑定dataTable     应当在数据库中转换为double再导入到excel
                worksheetRawMaterial.Import(sourceList[i].dataTable, true, sourceList[i].startRowIndex + 1, 1);

                //写标准
                worksheetRawMaterial.Rows.Insert(sourceList[i].startRowIndex + 2);
                worksheetRawMaterial.Rows.Insert(sourceList[i].startRowIndex + 2);
                worksheetRawMaterial[sourceList[i].startRowIndex + 2, 2].Value = "LSL";
                worksheetRawMaterial[sourceList[i].startRowIndex + 3, 2].Value = "USL";
                for (int j = 0; j < 4; j++)
                {
                    //1
                    WriteRawStanard(sourceList[i].startRowIndex + 2, 3, sourceList[i].standardRawList.Where(m => m.TestItemID == CommonData.TestItem_SP_ID).FirstOrDefault());
                    //2
                    WriteRawStanard(sourceList[i].startRowIndex + 2, 4, sourceList[i].standardRawList.Where(m => m.TestItemID == CommonData.TestItem_Mositure_ID).FirstOrDefault());
                    //3
                    WriteRawStanard(sourceList[i].startRowIndex + 2, 5, sourceList[i].standardRawList.Where(m => m.TestItemID == CommonData.TestItem_BMCI_ID).FirstOrDefault());
                    //4
                    WriteRawStanard(sourceList[i].startRowIndex + 2, 6, sourceList[i].standardRawList.Where(m => m.TestItemID == CommonData.TestItem_EnglarViscosity_ID).FirstOrDefault());
                }

                //count 等计算
                worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 5, 1].Value = "Count";
                worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 6, 1].Value = "Avg.";
                worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 7, 1].Value = "Max.";
                worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 8, 1].Value = "Min.";
                worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 9, 1].Value = "Std.";
                for (int j = 3; j < 7; j++)
                {
                    Cell cellLT = worksheetRawMaterial[sourceList[i].startRowIndex + 4, j];
                    Cell cellRB = worksheetRawMaterial[sourceList[i].startRowIndex + 4 + sourceList[i].dataTable.Rows.Count - 1, j];

                    //Count  =COUNTA(P2:P36)
                    //string formulaCount = "COUNTIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">0\")";
                    string formulaCount = "COUNTA(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")";
                    worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 5, j].ArrayFormula = formulaCount;
                    //avg
                    string formulaAvg = @"=IFERROR(AVERAGEIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">=0\"," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "),\"\")";
                    worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 6, j].ArrayFormula = formulaAvg;
                    //max    =MAX(IF((E151:E210>0),E151:E210))
                    string formulaMax = "=MAX(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 7, j].ArrayFormula = formulaMax;
                    //Min   =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMin = "=Min(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 8, j].ArrayFormula = formulaMin;
                    //  =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEV = "=IFERROR(STDEV(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")),\"\")";
                    worksheetRawMaterial[sourceList[i].startRowIndex + sourceList[i].dataTable.Rows.Count + 9, j].ArrayFormula = formulaSTDEV;
                }
                RawDecorateOnce(sourceList[i]);
            }

    

        }

        private void WriteRawStanard(int rowLSL, int column, StandardRaw standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheet = workbook.Worksheets["1)RawMaterial"];
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheet[rowLSL, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheet[rowLSL + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }

        }
        private void DecorateRawReport(DateTime startDate, DateTime endDate)
        {
            //1:写标题
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetRawMaterial = workbook.Worksheets["1)RawMaterial"];



            worksheetRawMaterial[0, 0].Value = "1. Analysis  result of CB raw materials \r\n (" + startDate.ToShortDateString() + "--" + endDate.ToShortDateString() + ")";   //\r\n

            worksheetRawMaterial.Rows[0].RowHeight = 110;
            //第二列加宽
            worksheetRawMaterial.Columns[1].Width = 310;

        }

        private void RawDecorateOnce(RawMaterialMonthReportModel monthReport)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetRawMaterial = workbook.Worksheets["1)RawMaterial"];
            //边框
            Range range = worksheetRawMaterial.Range.FromLTRB(1, monthReport.startRowIndex + 1, 12, monthReport.endRowIndex);
            range.SetInsideBorders(Color.Black, BorderLineStyle.Dashed);
            range.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
            worksheetRawMaterial.Rows[monthReport.startRowIndex + 1].RowHeight = 140;

            Formatting rangeFormatting1 = range.BeginUpdateFormatting();
            rangeFormatting1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            range.EndUpdateFormatting(rangeFormatting1);

            //合并Spec'
            Range rangeSpec = worksheetRawMaterial.Range.FromLTRB(1, monthReport.startRowIndex + 2, 1, monthReport.startRowIndex + 3);
            worksheetRawMaterial.MergeCells(rangeSpec);
            worksheetRawMaterial[monthReport.startRowIndex + 2, 1].Value = "Spec'";

            Formatting rangeFormatting = rangeSpec.BeginUpdateFormatting();
            rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            rangeSpec.EndUpdateFormatting(rangeFormatting);

        }


        #endregion

        #region Do报告相关方法

        private void InitDoReport(DateTime startDate, DateTime endDate)
        {
            int startRowIndex = 1;
            int startRowIndexMonth = 0;
            int startRowIndexYear = 0;
            
            List<Good> goodsSemiList = db.Goods.Where(m => m.GoodsTypeID == CommonData.GoodsType_Production_ID).ToList();
            List<DoMonthReportModel> DoData = new List<DoMonthReportModel>();
            //string sql = "SELECT [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[ProductionLineName] AS [ProductionLineName], [Project31].[ProductionGroupName] AS [ProductionGroupName], [Project31].[SendDate] AS [SendDate], [Project31].[Remark] AS [Remark], [Project31].[EmpName] AS [EmpName], CONVERT(float,[Project31].[C2]) AS [IA], CONVERT(float,[Project31].[C3]) AS [DBP], CONVERT(float,[Project31].[C4]) AS [IPH(AVG)], CONVERT(float,[Project31].[C5]) AS [IPH(High)],CONVERT(float, [Project31].[C6]) AS [IPH(Low)], CONVERT(float,[Project31].[C7]) AS [Fines], CONVERT(float,[Project31].[C8]) AS [HL], CONVERT(float,[Project31].[C9]) AS [Sieve Residue#35], CONVERT(float,[Project31].[C10]) AS [Sieve Residue#100], CONVERT(float,[Project31].[C11]) AS [Sieve Residue#325] FROM ( SELECT [Project30].[ReportSemiID] AS [ReportSemiID], [Project30].[GoodsID] AS [GoodsID], [Project30].[SamplingPlaceID] AS [SamplingPlaceID], [Project30].[ProductionLineID] AS [ProductionLineID], [Project30].[ProductionGroupID] AS [ProductionGroupID], [Project30].[SendDate] AS [SendDate], [Project30].[Remark] AS [Remark], [Project30].[LoginUserID] AS [LoginUserID], [Project30].[AddDateTime] AS [AddDateTime], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[ProductionLineName] AS [ProductionLineName], [Project30].[ProductionGroupName] AS [ProductionGroupName], [Project30].[EmpName] AS [EmpName], 1 AS [C1], [Project30].[C1] AS [C2], [Project30].[C2] AS [C3], [Project30].[C3] AS [C4], [Project30].[C4] AS [C5], [Project30].[C5] AS [C6], [Project30].[C6] AS [C7], [Project30].[C7] AS [C8], [Project30].[C8] AS [C9], [Project30].[C9] AS [C10], [Project30].[C10] AS [C11] FROM ( SELECT [Project28].[ReportSemiID] AS [ReportSemiID], [Project28].[GoodsID] AS [GoodsID], [Project28].[SamplingPlaceID] AS [SamplingPlaceID], [Project28].[ProductionLineID] AS [ProductionLineID], [Project28].[ProductionGroupID] AS [ProductionGroupID], [Project28].[SendDate] AS [SendDate], [Project28].[Remark] AS [Remark], [Project28].[LoginUserID] AS [LoginUserID], [Project28].[AddDateTime] AS [AddDateTime], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[ProductionLineName] AS [ProductionLineName], [Project28].[ProductionGroupName] AS [ProductionGroupName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent16] WHERE ([Project28].[ReportSemiID] = [Extent16].[ReportSemiID]) AND ('14' = [Extent16].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportSemiID] AS [ReportSemiID], [Project27].[GoodsID] AS [GoodsID], [Project27].[SamplingPlaceID] AS [SamplingPlaceID], [Project27].[ProductionLineID] AS [ProductionLineID], [Project27].[ProductionGroupID] AS [ProductionGroupID], [Project27].[SendDate] AS [SendDate], [Project27].[Remark] AS [Remark], [Project27].[LoginUserID] AS [LoginUserID], [Project27].[AddDateTime] AS [AddDateTime], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[ProductionLineName] AS [ProductionLineName], [Project27].[ProductionGroupName] AS [ProductionGroupName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportSemiID] AS [ReportSemiID], [Project25].[GoodsID] AS [GoodsID], [Project25].[SamplingPlaceID] AS [SamplingPlaceID], [Project25].[ProductionLineID] AS [ProductionLineID], [Project25].[ProductionGroupID] AS [ProductionGroupID], [Project25].[SendDate] AS [SendDate], [Project25].[Remark] AS [Remark], [Project25].[LoginUserID] AS [LoginUserID], [Project25].[AddDateTime] AS [AddDateTime], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[ProductionLineName] AS [ProductionLineName], [Project25].[ProductionGroupName] AS [ProductionGroupName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent15] WHERE ([Project25].[ReportSemiID] = [Extent15].[ReportSemiID]) AND ('13' = [Extent15].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportSemiID] AS [ReportSemiID], [Project24].[GoodsID] AS [GoodsID], [Project24].[SamplingPlaceID] AS [SamplingPlaceID], [Project24].[ProductionLineID] AS [ProductionLineID], [Project24].[ProductionGroupID] AS [ProductionGroupID], [Project24].[SendDate] AS [SendDate], [Project24].[Remark] AS [Remark], [Project24].[LoginUserID] AS [LoginUserID], [Project24].[AddDateTime] AS [AddDateTime], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[ProductionLineName] AS [ProductionLineName], [Project24].[ProductionGroupName] AS [ProductionGroupName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportSemiID] AS [ReportSemiID], [Project22].[GoodsID] AS [GoodsID], [Project22].[SamplingPlaceID] AS [SamplingPlaceID], [Project22].[ProductionLineID] AS [ProductionLineID], [Project22].[ProductionGroupID] AS [ProductionGroupID], [Project22].[SendDate] AS [SendDate], [Project22].[Remark] AS [Remark], [Project22].[LoginUserID] AS [LoginUserID], [Project22].[AddDateTime] AS [AddDateTime], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[ProductionLineName] AS [ProductionLineName], [Project22].[ProductionGroupName] AS [ProductionGroupName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent14] WHERE ([Project22].[ReportSemiID] = [Extent14].[ReportSemiID]) AND ('12' = [Extent14].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportSemiID] AS [ReportSemiID], [Project21].[GoodsID] AS [GoodsID], [Project21].[SamplingPlaceID] AS [SamplingPlaceID], [Project21].[ProductionLineID] AS [ProductionLineID], [Project21].[ProductionGroupID] AS [ProductionGroupID], [Project21].[SendDate] AS [SendDate], [Project21].[Remark] AS [Remark], [Project21].[LoginUserID] AS [LoginUserID], [Project21].[AddDateTime] AS [AddDateTime], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[ProductionLineName] AS [ProductionLineName], [Project21].[ProductionGroupName] AS [ProductionGroupName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportSemiID] AS [ReportSemiID], [Project19].[GoodsID] AS [GoodsID], [Project19].[SamplingPlaceID] AS [SamplingPlaceID], [Project19].[ProductionLineID] AS [ProductionLineID], [Project19].[ProductionGroupID] AS [ProductionGroupID], [Project19].[SendDate] AS [SendDate], [Project19].[Remark] AS [Remark], [Project19].[LoginUserID] AS [LoginUserID], [Project19].[AddDateTime] AS [AddDateTime], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[ProductionLineName] AS [ProductionLineName], [Project19].[ProductionGroupName] AS [ProductionGroupName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent13] WHERE ([Project19].[ReportSemiID] = [Extent13].[ReportSemiID]) AND ('10' = [Extent13].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportSemiID] AS [ReportSemiID], [Project18].[GoodsID] AS [GoodsID], [Project18].[SamplingPlaceID] AS [SamplingPlaceID], [Project18].[ProductionLineID] AS [ProductionLineID], [Project18].[ProductionGroupID] AS [ProductionGroupID], [Project18].[SendDate] AS [SendDate], [Project18].[Remark] AS [Remark], [Project18].[LoginUserID] AS [LoginUserID], [Project18].[AddDateTime] AS [AddDateTime], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[ProductionLineName] AS [ProductionLineName], [Project18].[ProductionGroupName] AS [ProductionGroupName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportSemiID] AS [ReportSemiID], [Project16].[GoodsID] AS [GoodsID], [Project16].[SamplingPlaceID] AS [SamplingPlaceID], [Project16].[ProductionLineID] AS [ProductionLineID], [Project16].[ProductionGroupID] AS [ProductionGroupID], [Project16].[SendDate] AS [SendDate], [Project16].[Remark] AS [Remark], [Project16].[LoginUserID] AS [LoginUserID], [Project16].[AddDateTime] AS [AddDateTime], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[ProductionLineName] AS [ProductionLineName], [Project16].[ProductionGroupName] AS [ProductionGroupName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent12] WHERE ([Project16].[ReportSemiID] = [Extent12].[ReportSemiID]) AND ('9' = [Extent12].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportSemiID] AS [ReportSemiID], [Project15].[GoodsID] AS [GoodsID], [Project15].[SamplingPlaceID] AS [SamplingPlaceID], [Project15].[ProductionLineID] AS [ProductionLineID], [Project15].[ProductionGroupID] AS [ProductionGroupID], [Project15].[SendDate] AS [SendDate], [Project15].[Remark] AS [Remark], [Project15].[LoginUserID] AS [LoginUserID], [Project15].[AddDateTime] AS [AddDateTime], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[ProductionLineName] AS [ProductionLineName], [Project15].[ProductionGroupName] AS [ProductionGroupName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportSemiID] AS [ReportSemiID], [Project13].[GoodsID] AS [GoodsID], [Project13].[SamplingPlaceID] AS [SamplingPlaceID], [Project13].[ProductionLineID] AS [ProductionLineID], [Project13].[ProductionGroupID] AS [ProductionGroupID], [Project13].[SendDate] AS [SendDate], [Project13].[Remark] AS [Remark], [Project13].[LoginUserID] AS [LoginUserID], [Project13].[AddDateTime] AS [AddDateTime], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[ProductionLineName] AS [ProductionLineName], [Project13].[ProductionGroupName] AS [ProductionGroupName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent11] WHERE ([Project13].[ReportSemiID] = [Extent11].[ReportSemiID]) AND ('30' = [Extent11].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportSemiID] AS [ReportSemiID], [Project12].[GoodsID] AS [GoodsID], [Project12].[SamplingPlaceID] AS [SamplingPlaceID], [Project12].[ProductionLineID] AS [ProductionLineID], [Project12].[ProductionGroupID] AS [ProductionGroupID], [Project12].[SendDate] AS [SendDate], [Project12].[Remark] AS [Remark], [Project12].[LoginUserID] AS [LoginUserID], [Project12].[AddDateTime] AS [AddDateTime], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[ProductionLineName] AS [ProductionLineName], [Project12].[ProductionGroupName] AS [ProductionGroupName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportSemiID] AS [ReportSemiID], [Project10].[GoodsID] AS [GoodsID], [Project10].[SamplingPlaceID] AS [SamplingPlaceID], [Project10].[ProductionLineID] AS [ProductionLineID], [Project10].[ProductionGroupID] AS [ProductionGroupID], [Project10].[SendDate] AS [SendDate], [Project10].[Remark] AS [Remark], [Project10].[LoginUserID] AS [LoginUserID], [Project10].[AddDateTime] AS [AddDateTime], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[ProductionLineName] AS [ProductionLineName], [Project10].[ProductionGroupName] AS [ProductionGroupName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent10] WHERE ([Project10].[ReportSemiID] = [Extent10].[ReportSemiID]) AND ('8' = [Extent10].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportSemiID] AS [ReportSemiID], [Project9].[GoodsID] AS [GoodsID], [Project9].[SamplingPlaceID] AS [SamplingPlaceID], [Project9].[ProductionLineID] AS [ProductionLineID], [Project9].[ProductionGroupID] AS [ProductionGroupID], [Project9].[SendDate] AS [SendDate], [Project9].[Remark] AS [Remark], [Project9].[LoginUserID] AS [LoginUserID], [Project9].[AddDateTime] AS [AddDateTime], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[ProductionLineName] AS [ProductionLineName], [Project9].[ProductionGroupName] AS [ProductionGroupName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportSemiID] AS [ReportSemiID], [Project7].[GoodsID] AS [GoodsID], [Project7].[SamplingPlaceID] AS [SamplingPlaceID], [Project7].[ProductionLineID] AS [ProductionLineID], [Project7].[ProductionGroupID] AS [ProductionGroupID], [Project7].[SendDate] AS [SendDate], [Project7].[Remark] AS [Remark], [Project7].[LoginUserID] AS [LoginUserID], [Project7].[AddDateTime] AS [AddDateTime], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[ProductionLineName] AS [ProductionLineName], [Project7].[ProductionGroupName] AS [ProductionGroupName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent9] WHERE ([Project7].[ReportSemiID] = [Extent9].[ReportSemiID]) AND ('46' = [Extent9].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportSemiID] AS [ReportSemiID], [Project6].[GoodsID] AS [GoodsID], [Project6].[SamplingPlaceID] AS [SamplingPlaceID], [Project6].[ProductionLineID] AS [ProductionLineID], [Project6].[ProductionGroupID] AS [ProductionGroupID], [Project6].[SendDate] AS [SendDate], [Project6].[Remark] AS [Remark], [Project6].[LoginUserID] AS [LoginUserID], [Project6].[AddDateTime] AS [AddDateTime], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[ProductionLineName] AS [ProductionLineName], [Project6].[ProductionGroupName] AS [ProductionGroupName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportSemiID] AS [ReportSemiID], [Project4].[GoodsID] AS [GoodsID], [Project4].[SamplingPlaceID] AS [SamplingPlaceID], [Project4].[ProductionLineID] AS [ProductionLineID], [Project4].[ProductionGroupID] AS [ProductionGroupID], [Project4].[SendDate] AS [SendDate], [Project4].[Remark] AS [Remark], [Project4].[LoginUserID] AS [LoginUserID], [Project4].[AddDateTime] AS [AddDateTime], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[ProductionLineName] AS [ProductionLineName], [Project4].[ProductionGroupName] AS [ProductionGroupName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent8] WHERE ([Project4].[ReportSemiID] = [Extent8].[ReportSemiID]) AND ('7' = [Extent8].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportSemiID] AS [ReportSemiID], [Project3].[GoodsID] AS [GoodsID], [Project3].[SamplingPlaceID] AS [SamplingPlaceID], [Project3].[ProductionLineID] AS [ProductionLineID], [Project3].[ProductionGroupID] AS [ProductionGroupID], [Project3].[SendDate] AS [SendDate], [Project3].[Remark] AS [Remark], [Project3].[LoginUserID] AS [LoginUserID], [Project3].[AddDateTime] AS [AddDateTime], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[ProductionLineName] AS [ProductionLineName], [Project3].[ProductionGroupName] AS [ProductionGroupName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportSemiID] AS [ReportSemiID], [Project1].[GoodsID] AS [GoodsID], [Project1].[SamplingPlaceID] AS [SamplingPlaceID], [Project1].[ProductionLineID] AS [ProductionLineID], [Project1].[ProductionGroupID] AS [ProductionGroupID], [Project1].[SendDate] AS [SendDate], [Project1].[Remark] AS [Remark], [Project1].[LoginUserID] AS [LoginUserID], [Project1].[AddDateTime] AS [AddDateTime], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[ProductionLineName] AS [ProductionLineName], [Project1].[ProductionGroupName] AS [ProductionGroupName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent7] WHERE ([Project1].[ReportSemiID] = [Extent7].[ReportSemiID]) AND ('1' = [Extent7].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportSemiID] AS [ReportSemiID], [Filter1].[GoodsID1] AS [GoodsID], [Filter1].[SamplingPlaceID1] AS [SamplingPlaceID], [Filter1].[ProductionLineID1] AS [ProductionLineID], [Filter1].[ProductionGroupID1] AS [ProductionGroupID], [Filter1].[SendDate] AS [SendDate], [Filter1].[Remark1] AS [Remark], [Filter1].[LoginUserID] AS [LoginUserID], [Filter1].[AddDateTime] AS [AddDateTime], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Filter1].[ProductionLineName] AS [ProductionLineName], [Filter1].[ProductionGroupName] AS [ProductionGroupName], [Extent6].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportSemiID] AS [ReportSemiID], [Extent1].[GoodsID] AS [GoodsID1], [Extent1].[SamplingPlaceID] AS [SamplingPlaceID1], [Extent1].[ProductionLineID] AS [ProductionLineID1], [Extent1].[ProductionGroupID] AS [ProductionGroupID1], [Extent1].[SendDate] AS [SendDate], [Extent1].[Remark] AS [Remark1], [Extent1].[LoginUserID] AS [LoginUserID], [Extent1].[AddDateTime] AS [AddDateTime], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[ProductionLineName] AS [ProductionLineName], [Extent5].[ProductionGroupName] AS [ProductionGroupName] FROM [dbo].[ReportSemis] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaces] AS [Extent3] ON [Extent1].[SamplingPlaceID] = [Extent3].[SamplingPlaceID] INNER JOIN [dbo].[ProductionLines] AS [Extent4] ON [Extent1].[ProductionLineID] = [Extent4].[ProductionLineID] INNER JOIN [dbo].[ProductionGroups] AS [Extent5] ON [Extent1].[ProductionGroupID] = [Extent5].[ProductionGroupID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('5' = [Extent1].[SamplingPlaceID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent6] ON [Filter1].[LoginUserID] = [Extent6].[LoginUserID] WHERE ([Filter1].[SendDate] >= @StartDate) AND ([Filter1].[SendDate] <= @EndDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ORDER BY [Project31].[SendDate] ASC";
            string sql = "SELECT [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[ProductionLineName] AS [ProductionLineName], [Project31].[ProductionGroupName] AS [ProductionGroupName], [Project31].[SendDate] AS [SendDate], [Project31].[Remark] AS [Remark], [Project31].[EmpName] AS [EmpName], CASE [Project31].[C2] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C2] ) END AS [IA], CASE [Project31].[C3] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C3] ) END AS [DBP], CASE [Project31].[C4] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C4] ) END AS [IPH(AVG)], CASE [Project31].[C5] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C5] ) END AS [IPH(High)], CASE [Project31].[C6] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C6] ) END AS [IPH(Low)], CASE [Project31].[C7] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C7] ) END AS [Fines], CASE [Project31].[C8] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C8] ) END AS [HL], CASE [Project31].[C9] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C9] ) END AS [Sieve Residue#35], CASE [Project31].[C10] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C10]) END AS [Sieve Residue#100], CASE [Project31].[C11] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C11]) END AS [Sieve Residue#325] FROM ( SELECT [Project30].[ReportSemiID] AS [ReportSemiID], [Project30].[GoodsID] AS [GoodsID], [Project30].[SamplingPlaceID] AS [SamplingPlaceID], [Project30].[ProductionLineID] AS [ProductionLineID], [Project30].[ProductionGroupID] AS [ProductionGroupID], [Project30].[SendDate] AS [SendDate], [Project30].[Remark] AS [Remark], [Project30].[LoginUserID] AS [LoginUserID], [Project30].[AddDateTime] AS [AddDateTime], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[ProductionLineName] AS [ProductionLineName], [Project30].[ProductionGroupName] AS [ProductionGroupName], [Project30].[EmpName] AS [EmpName], 1 AS [C1], [Project30].[C1] AS [C2], [Project30].[C2] AS [C3], [Project30].[C3] AS [C4], [Project30].[C4] AS [C5], [Project30].[C5] AS [C6], [Project30].[C6] AS [C7], [Project30].[C7] AS [C8], [Project30].[C8] AS [C9], [Project30].[C9] AS [C10], [Project30].[C10] AS [C11] FROM ( SELECT [Project28].[ReportSemiID] AS [ReportSemiID], [Project28].[GoodsID] AS [GoodsID], [Project28].[SamplingPlaceID] AS [SamplingPlaceID], [Project28].[ProductionLineID] AS [ProductionLineID], [Project28].[ProductionGroupID] AS [ProductionGroupID], [Project28].[SendDate] AS [SendDate], [Project28].[Remark] AS [Remark], [Project28].[LoginUserID] AS [LoginUserID], [Project28].[AddDateTime] AS [AddDateTime], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[ProductionLineName] AS [ProductionLineName], [Project28].[ProductionGroupName] AS [ProductionGroupName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent16] WHERE ([Project28].[ReportSemiID] = [Extent16].[ReportSemiID]) AND ('14' = [Extent16].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportSemiID] AS [ReportSemiID], [Project27].[GoodsID] AS [GoodsID], [Project27].[SamplingPlaceID] AS [SamplingPlaceID], [Project27].[ProductionLineID] AS [ProductionLineID], [Project27].[ProductionGroupID] AS [ProductionGroupID], [Project27].[SendDate] AS [SendDate], [Project27].[Remark] AS [Remark], [Project27].[LoginUserID] AS [LoginUserID], [Project27].[AddDateTime] AS [AddDateTime], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[ProductionLineName] AS [ProductionLineName], [Project27].[ProductionGroupName] AS [ProductionGroupName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportSemiID] AS [ReportSemiID], [Project25].[GoodsID] AS [GoodsID], [Project25].[SamplingPlaceID] AS [SamplingPlaceID], [Project25].[ProductionLineID] AS [ProductionLineID], [Project25].[ProductionGroupID] AS [ProductionGroupID], [Project25].[SendDate] AS [SendDate], [Project25].[Remark] AS [Remark], [Project25].[LoginUserID] AS [LoginUserID], [Project25].[AddDateTime] AS [AddDateTime], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[ProductionLineName] AS [ProductionLineName], [Project25].[ProductionGroupName] AS [ProductionGroupName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent15] WHERE ([Project25].[ReportSemiID] = [Extent15].[ReportSemiID]) AND ('13' = [Extent15].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportSemiID] AS [ReportSemiID], [Project24].[GoodsID] AS [GoodsID], [Project24].[SamplingPlaceID] AS [SamplingPlaceID], [Project24].[ProductionLineID] AS [ProductionLineID], [Project24].[ProductionGroupID] AS [ProductionGroupID], [Project24].[SendDate] AS [SendDate], [Project24].[Remark] AS [Remark], [Project24].[LoginUserID] AS [LoginUserID], [Project24].[AddDateTime] AS [AddDateTime], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[ProductionLineName] AS [ProductionLineName], [Project24].[ProductionGroupName] AS [ProductionGroupName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportSemiID] AS [ReportSemiID], [Project22].[GoodsID] AS [GoodsID], [Project22].[SamplingPlaceID] AS [SamplingPlaceID], [Project22].[ProductionLineID] AS [ProductionLineID], [Project22].[ProductionGroupID] AS [ProductionGroupID], [Project22].[SendDate] AS [SendDate], [Project22].[Remark] AS [Remark], [Project22].[LoginUserID] AS [LoginUserID], [Project22].[AddDateTime] AS [AddDateTime], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[ProductionLineName] AS [ProductionLineName], [Project22].[ProductionGroupName] AS [ProductionGroupName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent14] WHERE ([Project22].[ReportSemiID] = [Extent14].[ReportSemiID]) AND ('12' = [Extent14].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportSemiID] AS [ReportSemiID], [Project21].[GoodsID] AS [GoodsID], [Project21].[SamplingPlaceID] AS [SamplingPlaceID], [Project21].[ProductionLineID] AS [ProductionLineID], [Project21].[ProductionGroupID] AS [ProductionGroupID], [Project21].[SendDate] AS [SendDate], [Project21].[Remark] AS [Remark], [Project21].[LoginUserID] AS [LoginUserID], [Project21].[AddDateTime] AS [AddDateTime], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[ProductionLineName] AS [ProductionLineName], [Project21].[ProductionGroupName] AS [ProductionGroupName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportSemiID] AS [ReportSemiID], [Project19].[GoodsID] AS [GoodsID], [Project19].[SamplingPlaceID] AS [SamplingPlaceID], [Project19].[ProductionLineID] AS [ProductionLineID], [Project19].[ProductionGroupID] AS [ProductionGroupID], [Project19].[SendDate] AS [SendDate], [Project19].[Remark] AS [Remark], [Project19].[LoginUserID] AS [LoginUserID], [Project19].[AddDateTime] AS [AddDateTime], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[ProductionLineName] AS [ProductionLineName], [Project19].[ProductionGroupName] AS [ProductionGroupName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent13] WHERE ([Project19].[ReportSemiID] = [Extent13].[ReportSemiID]) AND ('10' = [Extent13].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportSemiID] AS [ReportSemiID], [Project18].[GoodsID] AS [GoodsID], [Project18].[SamplingPlaceID] AS [SamplingPlaceID], [Project18].[ProductionLineID] AS [ProductionLineID], [Project18].[ProductionGroupID] AS [ProductionGroupID], [Project18].[SendDate] AS [SendDate], [Project18].[Remark] AS [Remark], [Project18].[LoginUserID] AS [LoginUserID], [Project18].[AddDateTime] AS [AddDateTime], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[ProductionLineName] AS [ProductionLineName], [Project18].[ProductionGroupName] AS [ProductionGroupName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportSemiID] AS [ReportSemiID], [Project16].[GoodsID] AS [GoodsID], [Project16].[SamplingPlaceID] AS [SamplingPlaceID], [Project16].[ProductionLineID] AS [ProductionLineID], [Project16].[ProductionGroupID] AS [ProductionGroupID], [Project16].[SendDate] AS [SendDate], [Project16].[Remark] AS [Remark], [Project16].[LoginUserID] AS [LoginUserID], [Project16].[AddDateTime] AS [AddDateTime], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[ProductionLineName] AS [ProductionLineName], [Project16].[ProductionGroupName] AS [ProductionGroupName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent12] WHERE ([Project16].[ReportSemiID] = [Extent12].[ReportSemiID]) AND ('9' = [Extent12].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportSemiID] AS [ReportSemiID], [Project15].[GoodsID] AS [GoodsID], [Project15].[SamplingPlaceID] AS [SamplingPlaceID], [Project15].[ProductionLineID] AS [ProductionLineID], [Project15].[ProductionGroupID] AS [ProductionGroupID], [Project15].[SendDate] AS [SendDate], [Project15].[Remark] AS [Remark], [Project15].[LoginUserID] AS [LoginUserID], [Project15].[AddDateTime] AS [AddDateTime], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[ProductionLineName] AS [ProductionLineName], [Project15].[ProductionGroupName] AS [ProductionGroupName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportSemiID] AS [ReportSemiID], [Project13].[GoodsID] AS [GoodsID], [Project13].[SamplingPlaceID] AS [SamplingPlaceID], [Project13].[ProductionLineID] AS [ProductionLineID], [Project13].[ProductionGroupID] AS [ProductionGroupID], [Project13].[SendDate] AS [SendDate], [Project13].[Remark] AS [Remark], [Project13].[LoginUserID] AS [LoginUserID], [Project13].[AddDateTime] AS [AddDateTime], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[ProductionLineName] AS [ProductionLineName], [Project13].[ProductionGroupName] AS [ProductionGroupName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent11] WHERE ([Project13].[ReportSemiID] = [Extent11].[ReportSemiID]) AND ('30' = [Extent11].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportSemiID] AS [ReportSemiID], [Project12].[GoodsID] AS [GoodsID], [Project12].[SamplingPlaceID] AS [SamplingPlaceID], [Project12].[ProductionLineID] AS [ProductionLineID], [Project12].[ProductionGroupID] AS [ProductionGroupID], [Project12].[SendDate] AS [SendDate], [Project12].[Remark] AS [Remark], [Project12].[LoginUserID] AS [LoginUserID], [Project12].[AddDateTime] AS [AddDateTime], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[ProductionLineName] AS [ProductionLineName], [Project12].[ProductionGroupName] AS [ProductionGroupName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportSemiID] AS [ReportSemiID], [Project10].[GoodsID] AS [GoodsID], [Project10].[SamplingPlaceID] AS [SamplingPlaceID], [Project10].[ProductionLineID] AS [ProductionLineID], [Project10].[ProductionGroupID] AS [ProductionGroupID], [Project10].[SendDate] AS [SendDate], [Project10].[Remark] AS [Remark], [Project10].[LoginUserID] AS [LoginUserID], [Project10].[AddDateTime] AS [AddDateTime], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[ProductionLineName] AS [ProductionLineName], [Project10].[ProductionGroupName] AS [ProductionGroupName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent10] WHERE ([Project10].[ReportSemiID] = [Extent10].[ReportSemiID]) AND ('8' = [Extent10].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportSemiID] AS [ReportSemiID], [Project9].[GoodsID] AS [GoodsID], [Project9].[SamplingPlaceID] AS [SamplingPlaceID], [Project9].[ProductionLineID] AS [ProductionLineID], [Project9].[ProductionGroupID] AS [ProductionGroupID], [Project9].[SendDate] AS [SendDate], [Project9].[Remark] AS [Remark], [Project9].[LoginUserID] AS [LoginUserID], [Project9].[AddDateTime] AS [AddDateTime], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[ProductionLineName] AS [ProductionLineName], [Project9].[ProductionGroupName] AS [ProductionGroupName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportSemiID] AS [ReportSemiID], [Project7].[GoodsID] AS [GoodsID], [Project7].[SamplingPlaceID] AS [SamplingPlaceID], [Project7].[ProductionLineID] AS [ProductionLineID], [Project7].[ProductionGroupID] AS [ProductionGroupID], [Project7].[SendDate] AS [SendDate], [Project7].[Remark] AS [Remark], [Project7].[LoginUserID] AS [LoginUserID], [Project7].[AddDateTime] AS [AddDateTime], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[ProductionLineName] AS [ProductionLineName], [Project7].[ProductionGroupName] AS [ProductionGroupName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent9] WHERE ([Project7].[ReportSemiID] = [Extent9].[ReportSemiID]) AND ('46' = [Extent9].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportSemiID] AS [ReportSemiID], [Project6].[GoodsID] AS [GoodsID], [Project6].[SamplingPlaceID] AS [SamplingPlaceID], [Project6].[ProductionLineID] AS [ProductionLineID], [Project6].[ProductionGroupID] AS [ProductionGroupID], [Project6].[SendDate] AS [SendDate], [Project6].[Remark] AS [Remark], [Project6].[LoginUserID] AS [LoginUserID], [Project6].[AddDateTime] AS [AddDateTime], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[ProductionLineName] AS [ProductionLineName], [Project6].[ProductionGroupName] AS [ProductionGroupName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportSemiID] AS [ReportSemiID], [Project4].[GoodsID] AS [GoodsID], [Project4].[SamplingPlaceID] AS [SamplingPlaceID], [Project4].[ProductionLineID] AS [ProductionLineID], [Project4].[ProductionGroupID] AS [ProductionGroupID], [Project4].[SendDate] AS [SendDate], [Project4].[Remark] AS [Remark], [Project4].[LoginUserID] AS [LoginUserID], [Project4].[AddDateTime] AS [AddDateTime], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[ProductionLineName] AS [ProductionLineName], [Project4].[ProductionGroupName] AS [ProductionGroupName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent8] WHERE ([Project4].[ReportSemiID] = [Extent8].[ReportSemiID]) AND ('7' = [Extent8].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportSemiID] AS [ReportSemiID], [Project3].[GoodsID] AS [GoodsID], [Project3].[SamplingPlaceID] AS [SamplingPlaceID], [Project3].[ProductionLineID] AS [ProductionLineID], [Project3].[ProductionGroupID] AS [ProductionGroupID], [Project3].[SendDate] AS [SendDate], [Project3].[Remark] AS [Remark], [Project3].[LoginUserID] AS [LoginUserID], [Project3].[AddDateTime] AS [AddDateTime], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[ProductionLineName] AS [ProductionLineName], [Project3].[ProductionGroupName] AS [ProductionGroupName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportSemiID] AS [ReportSemiID], [Project1].[GoodsID] AS [GoodsID], [Project1].[SamplingPlaceID] AS [SamplingPlaceID], [Project1].[ProductionLineID] AS [ProductionLineID], [Project1].[ProductionGroupID] AS [ProductionGroupID], [Project1].[SendDate] AS [SendDate], [Project1].[Remark] AS [Remark], [Project1].[LoginUserID] AS [LoginUserID], [Project1].[AddDateTime] AS [AddDateTime], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[ProductionLineName] AS [ProductionLineName], [Project1].[ProductionGroupName] AS [ProductionGroupName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent7] WHERE ([Project1].[ReportSemiID] = [Extent7].[ReportSemiID]) AND ('1' = [Extent7].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportSemiID] AS [ReportSemiID], [Filter1].[GoodsID1] AS [GoodsID], [Filter1].[SamplingPlaceID1] AS [SamplingPlaceID], [Filter1].[ProductionLineID1] AS [ProductionLineID], [Filter1].[ProductionGroupID1] AS [ProductionGroupID], [Filter1].[SendDate] AS [SendDate], [Filter1].[Remark1] AS [Remark], [Filter1].[LoginUserID] AS [LoginUserID], [Filter1].[AddDateTime] AS [AddDateTime], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Filter1].[ProductionLineName] AS [ProductionLineName], [Filter1].[ProductionGroupName] AS [ProductionGroupName], [Extent6].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportSemiID] AS [ReportSemiID], [Extent1].[GoodsID] AS [GoodsID1], [Extent1].[SamplingPlaceID] AS [SamplingPlaceID1], [Extent1].[ProductionLineID] AS [ProductionLineID1], [Extent1].[ProductionGroupID] AS [ProductionGroupID1], [Extent1].[SendDate] AS [SendDate], [Extent1].[Remark] AS [Remark1], [Extent1].[LoginUserID] AS [LoginUserID], [Extent1].[AddDateTime] AS [AddDateTime], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[ProductionLineName] AS [ProductionLineName], [Extent5].[ProductionGroupName] AS [ProductionGroupName] FROM [dbo].[ReportSemis] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaces] AS [Extent3] ON [Extent1].[SamplingPlaceID] = [Extent3].[SamplingPlaceID] INNER JOIN [dbo].[ProductionLines] AS [Extent4] ON [Extent1].[ProductionLineID] = [Extent4].[ProductionLineID] INNER JOIN [dbo].[ProductionGroups] AS [Extent5] ON [Extent1].[ProductionGroupID] = [Extent5].[ProductionGroupID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('5' = [Extent1].[SamplingPlaceID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent6] ON [Filter1].[LoginUserID] = [Extent6].[LoginUserID] WHERE ([Filter1].[SendDate] >= @StartDate) AND ([Filter1].[SendDate] <= @EndDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ORDER BY [Project31].[SendDate] ASC";
            foreach (var goods in goodsSemiList)
            {
                //this month
                SqlParameter startDateSqlParameterMonth = new SqlParameter("@StartDate", startDate);
                SqlParameter endDateSqlParameterMonth = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterMonth = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersMonth = new SqlParameter[] { startDateSqlParameterMonth, endDateSqlParameterMonth, GoodsIDSqlParameterMonth };
                //this year
                SqlParameter startDateSqlParameterYear = new SqlParameter("@StartDate", new DateTime(startDate.Year, 01, 01));
                SqlParameter endDateSqlParameterYear = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterYear = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersYear = new SqlParameter[] { startDateSqlParameterYear, endDateSqlParameterYear, GoodsIDSqlParameterYear };


                DoMonthReportModel reportModel = new DoMonthReportModel();
                reportModel.dataTableThisMonth = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersMonth);
                reportModel.dataTableThisYear = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersYear);

                reportModel.viewStartRowIndex = startRowIndex;
                reportModel.viewEndRowIndex = startRowIndex + 16 + 28 + 2;     //16 表格    28曲线图  2空行

                reportModel.monthDataStartRowIndex = startRowIndexMonth;
                reportModel.monthDataEndRowIndex = startRowIndexMonth + reportModel.dataTableThisMonth.Rows.Count + 8;

                reportModel.yearDataStartRowIndex = startRowIndexYear;
                reportModel.yearDataEndRowIndex = startRowIndexYear + reportModel.dataTableThisYear.Rows.Count + 8;

                reportModel.goodsName = goods.GoodsName;
                reportModel.standardSemiList = db.StandardSemis.Where(m => m.GoodsID == goods.GoodsID && m.SamplingPlaceID == CommonData.SamplingPlace_Do_ID).ToList();

                if (reportModel.dataTableThisMonth.Rows.Count > 0)
                {
                    DoData.Add(reportModel);
                    startRowIndex = reportModel.viewEndRowIndex + 2;
                    startRowIndexMonth = reportModel.monthDataEndRowIndex + 2;
                    startRowIndexYear = reportModel.yearDataEndRowIndex + 2;
                }
            }

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoDataThisMonth = workbook.Worksheets["DO_ThisMonthData"];
            Worksheet worksheetDoThisYear = workbook.Worksheets["DO_ThisYearData"];
            Worksheet worksheetDoView = workbook.Worksheets["2)DO"];

            for (int i = 0; i < DoData.Count; i++)
            {
                worksheetDoDataThisMonth.Import(DoData[i].dataTableThisMonth, true, DoData[i].monthDataStartRowIndex, 1);
                worksheetDoThisYear.Import(DoData[i].dataTableThisYear, true, DoData[i].yearDataStartRowIndex, 1);

                //写Month标准
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 6, 1].Value = "USL";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 6, 1].Value = "USL";
                WriteDoDataStanard(DoData[i], 8, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 9, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 14, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 15, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 16, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WriteDoDataStanard(DoData[i], 17, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());


                WriteDoViewStandard(DoData[i], 4, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 5, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 6, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 7, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 8, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 9, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WriteDoViewStandard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());

                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 5, 1].Value = "Count";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 0, 1].Value = "Cpk";

                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 5, 1].Value = "Count";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 0, 1].Value = "Cpk";

                //在MonthData中填写IA的下线 列
                WriteDoDataColumnStanard(DoData[i], 19, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault(), "IA");
                WriteDoDataColumnStanard(DoData[i], 21, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault(), "DBP");
                WriteDoDataColumnStanard(DoData[i], 23, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault(), "Fines");
                WriteDoDataColumnStanard(DoData[i], 25, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault(), "SR325");

                for (int c = 8; c < 18; c++)
                {
                    Cell cellLT = worksheetDoDataThisMonth[DoData[i].monthDataStartRowIndex + 1, c];
                    Cell cellRB = worksheetDoDataThisMonth[DoData[i].monthDataStartRowIndex + 1 + DoData[i].dataTableThisMonth.Rows.Count - 1, c];
                    //count Month  =COUNTA(P2:P36)
                    //string formulaCount = "COUNTIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">0\")";
                    string formulaCount = "COUNTA(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 5, c].ArrayFormula = formulaCount;
                    //avg Month
                    string formulaAvg = @"=IFERROR(AVERAGEIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">=0\"," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "),\"\")";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c].ArrayFormula = formulaAvg;
                    Cell avg = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //max Month   =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMax = "=MAX(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 1, c].ArrayFormula = formulaMax;
                    Cell MAX = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //Min Month    =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMin = "=MIN(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 2, c].ArrayFormula = formulaMin;
                    //std Month  =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEV = "=IFERROR(STDEV(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")),\"\")";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEV;
                    //cpk   Month
                    //string cellLSL = "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 7, c].GetReferenceA1();
                    //string cellUSL = "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 6, c].GetReferenceA1();
                    //string cellAVG = "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    //string cellStd = "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    string cellLSL = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSL = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVG = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStd = worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPK = "=IFERROR(IF(AND(" + cellUSL + "=\"\"," + cellLSL + "=\"\"),\"\",MIN((" + cellUSL + "-" + cellAVG + ")/3/" + cellStd + ",(" + cellAVG + "-" + cellLSL + ")/3/" + cellStd + ")),\"\")";
                    worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 0, c].ArrayFormula = formulaCPK;

                    string countMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKMonth = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetDoDataThisMonth[DoData[i].monthDataEndRowIndex - 0, c].GetReferenceA1();

                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 4, c - 4, countMonth);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 5, c - 4, avgMonth);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 6, c - 4, STDEVMonth);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 7, c - 4, MinMonth);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 8, c - 4, MaxMonth);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 9, c - 4, CPKMonth);



                    /////////////////////////////////////////////统计this Year
                    Cell cellLTYaer = worksheetDoThisYear[DoData[i].yearDataStartRowIndex + 1, c];
                    Cell cellRBYaer = worksheetDoThisYear[DoData[i].yearDataStartRowIndex + 1 + DoData[i].dataTableThisYear.Rows.Count - 1, c];
                    //count   =COUNTA(P2:P36)
                    string formulaCountYear = "COUNTA(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 5, c].Formula = formulaCountYear;
                    //avg Month
                    string formulaAvgYear = @"=IFERROR(AVERAGEIF(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ",\">=0\"," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "),\"\")";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, c].ArrayFormula = formulaAvgYear;
                    Cell avgYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //max Month   =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMaxYear = "=MAX(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 1, c].ArrayFormula = formulaMaxYear;
                    Cell MAXYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //Min Month   =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMinYear = "=MIN(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 2, c].ArrayFormula = formulaMinYear;
                    //std Month   =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEVYear = "=IFERROR(STDEV(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")),\"\")";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEVYear;
                    //cpk   Month   string cellLSLYear = "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellLSLYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSLYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVGYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStdYear = worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPKYear = "=IFERROR(IF(AND(" + cellUSLYear + "=\"\"," + cellLSLYear + "=\"\"),\"\",MIN((" + cellUSLYear + "-" + cellAVGYear + ")/3/" + cellStdYear + ",(" + cellAVGYear + "-" + cellLSLYear + ")/3/" + cellStdYear + ")),\"\")";
                    worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 0, c].ArrayFormula = formulaCPKYear;

                    string countYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetDoThisYear[DoData[i].yearDataEndRowIndex - 0, c].GetReferenceA1();

                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 10, c - 4, countYearFormula);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 11, c - 4, avgYearFormula);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 12, c - 4, STDEVYearFormula);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 13, c - 4, MinYearFormula);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 14, c - 4, MaxYearFormula);
                    DoWriteDataDetail(DoData[i].viewStartRowIndex + 15, c - 4, CPKYearFormula);

                }




                DoDecorate(DoData[i], startDate, endDate);
                DoWriteTitel(DoData[i], i);

                ///开始添加 曲线图
                int chartStartRow = DoData[i].viewStartRowIndex + 16;
                // 19 IA
                DoCreateChart(DoData[i], worksheetDoView[chartStartRow, 0], worksheetDoView[chartStartRow + 14, 6], 8, 19);
                // 21  dbp
                DoCreateChart(DoData[i], worksheetDoView[chartStartRow, 7], worksheetDoView[chartStartRow + 14, 13], 9, 21);
                // 23  dbp
                DoCreateChart(DoData[i], worksheetDoView[chartStartRow + 15, 0], worksheetDoView[chartStartRow + 15 + 14, 6], 13, 23);
                // 25  dbp
                DoCreateChart(DoData[i], worksheetDoView[chartStartRow + 15, 7], worksheetDoView[chartStartRow + 15 + 14, 13], 17, 25);
            }




        }

        //写Do标准
        private void WriteDoDataStanard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)DO"];
            Worksheet worksheetDO_ThisMonthData = workbook.Worksheets["DO_ThisMonthData"];
            Worksheet worksheetDO_ThisYearData = workbook.Worksheets["DO_ThisYearData"];


            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetDO_ThisMonthData[reportModel.monthDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                    worksheetDO_ThisYearData[reportModel.yearDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetDO_ThisMonthData[reportModel.monthDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                    worksheetDO_ThisYearData[reportModel.yearDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        private void WriteDoDataColumnStanard(DoMonthReportModel reportModel, int column, StandardSemi standard, string columnName)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)DO"];
            Worksheet worksheetDO_ThisMonthData = workbook.Worksheets["DO_ThisMonthData"];
            Worksheet worksheetDO_ThisYearData = workbook.Worksheets["DO_ThisYearData"];

            worksheetDO_ThisMonthData[reportModel.monthDataStartRowIndex, column].Value = columnName + "_LSL";
            worksheetDO_ThisMonthData[reportModel.monthDataStartRowIndex, column + 1].Value = columnName + "_USL";
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    Range rangeIA_LSL = worksheetDO_ThisMonthData.Range.FromLTRB(column, reportModel.monthDataStartRowIndex + 1, column, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    Range rangeIA_LSL = worksheetDO_ThisMonthData.Range.FromLTRB(column + 1, reportModel.monthDataStartRowIndex + 1, column + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        private void WriteDoViewStandard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)DO"];
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        private void DoWriteTitel(DoMonthReportModel semiReport, int NO)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDO = workbook.Worksheets["2)DO"];

            // 第一行  Unit    Grade   
            worksheetDO[semiReport.viewStartRowIndex, 0].Value = "Unit";
            worksheetDO[semiReport.viewStartRowIndex, 1].Value = "Grade";
            worksheetDO[semiReport.viewStartRowIndex, 2].Value = "Month";
            worksheetDO[semiReport.viewStartRowIndex, 3].Value = "Category";
            worksheetDO[semiReport.viewStartRowIndex, 4].Value = "IA(g/kg)";
            worksheetDO[semiReport.viewStartRowIndex, 5].Value = "DBP(ml/100g)";
            worksheetDO[semiReport.viewStartRowIndex, 6].Value = "IPH(gf)";
            worksheetDO[semiReport.viewStartRowIndex, 9].Value = "Fines(%)";
            worksheetDO[semiReport.viewStartRowIndex, 10].Value = "HL(%)";
            worksheetDO[semiReport.viewStartRowIndex, 11].Value = "Sieve Residue(ppm)";
            //第二行
            worksheetDO[semiReport.viewStartRowIndex + 1, 6].Value = "AVG";
            worksheetDO[semiReport.viewStartRowIndex + 1, 7].Value = "High";
            worksheetDO[semiReport.viewStartRowIndex + 1, 8].Value = "Low";
            worksheetDO[semiReport.viewStartRowIndex + 1, 11].Value = "#35";
            worksheetDO[semiReport.viewStartRowIndex + 1, 12].Value = "#100";
            worksheetDO[semiReport.viewStartRowIndex + 1, 13].Value = "#325";
            //合并单元格  横向 IPH     Sieve
            Range rangeIPH = worksheetDO.Range.FromLTRB(6, semiReport.viewStartRowIndex, 8, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeIPH);
            Range rangeSieve = worksheetDO.Range.FromLTRB(11, semiReport.viewStartRowIndex, 13, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeSieve);
            //合并单元格 zongxiang
            int[] intArray = new int[] { 0, 1, 2, 3, 4, 5, 9, 10 };
            foreach (int i in intArray)
            {
                Range rangeUnit = worksheetDO.Range.FromLTRB(i, semiReport.viewStartRowIndex, i, semiReport.viewStartRowIndex + 1);
                worksheetDO.MergeCells(rangeUnit);
            }
            //标题第一行加高
            RowCollection rows = worksheetDO.Rows;
            Row row_byIndex = rows[semiReport.viewStartRowIndex];
            row_byIndex.RowHeight = 140;
            //字体加粗  居中

            //合并Unit 下方单元格   Grade下方单元格
            Range rangeUnitDetail = worksheetDO.Range.FromLTRB(0, semiReport.viewStartRowIndex + 2, 0, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Value = NO + 1;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            Range rangeGradeDetail = worksheetDO.Range.FromLTRB(1, semiReport.viewStartRowIndex + 2, 1, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Value = semiReport.goodsName;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            worksheetDO.MergeCells(rangeUnitDetail);
            worksheetDO.MergeCells(rangeGradeDetail);
            //合并month下方 spec‘单元格
            Range rangeSpec = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 2, 2, semiReport.viewStartRowIndex + 3);
            worksheetDO.MergeCells(rangeSpec);
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Value = "spec'";
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 Month‘单元格
            Range rangeMonthCurrent = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 4, 2, semiReport.viewStartRowIndex + 9);
            worksheetDO.MergeCells(rangeMonthCurrent);
            // worksheetDO[semiReport.viewStartRowIndex + 4, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();       //当前月份
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 之前月份 ‘单元格
            Range rangeMonthBefore = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 10, 2, semiReport.viewStartRowIndex + 15);
            worksheetDO.MergeCells(rangeMonthBefore);

            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //Category
            worksheetDO[semiReport.viewStartRowIndex + 2, 3].Value = "LSL";
            worksheetDO[semiReport.viewStartRowIndex + 3, 3].Value = "USL";
            worksheetDO[semiReport.viewStartRowIndex + 4, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 5, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 6, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 7, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 8, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 9, 3].Value = "Cpk";

            worksheetDO[semiReport.viewStartRowIndex + 10, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 11, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 12, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 13, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 14, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 15, 3].Value = "Cpk";
        }
        private void DoWriteDataDetail(int row, int column, string formula)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["2)DO"];
            worksheetDoView[row, column].Formula = formula;
        }
        private void DoCreateChart(DoMonthReportModel reportModel, Cell TopLeftCell, Cell BottomRightCell, int columnValue, int columnLSL)
        {
            //  IA  DBP 
            //FInes SR#325
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["2)DO"];
            Worksheet worksheetDo_ThisMonth = workbook.Worksheets["DO_ThisMonthData"];

            Chart chartIA = worksheetDoView.Charts.Add(ChartType.ScatterLineMarkers);
            chartIA.TopLeftCell = TopLeftCell;
            chartIA.BottomRightCell = BottomRightCell;
            //创建IA的 曲线
            Range nameIARane = worksheetDo_ThisMonth.Range.FromLTRB(columnValue, reportModel.monthDataStartRowIndex, columnValue, reportModel.monthDataStartRowIndex);
            Range valueRange = worksheetDo_ThisMonth.Range.FromLTRB(columnValue, reportModel.monthDataStartRowIndex + 1, columnValue, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            Range agumentRage = worksheetDo_ThisMonth.Range.FromLTRB(5, reportModel.monthDataStartRowIndex + 1, 5, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameIARane, agumentRage, valueRange);

            //下限
            Range nameLSLRange = worksheetDo_ThisMonth.Range.FromLTRB(1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count + 1, 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count + 1);
            Range valueLSLRange = worksheetDo_ThisMonth.Range.FromLTRB(columnLSL, reportModel.monthDataStartRowIndex + 1, columnLSL, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameLSLRange, agumentRage, valueLSLRange);
            //上线
            Range nameUSLRange = worksheetDo_ThisMonth.Range.FromLTRB(1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count + 2, 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count + 2);
            Range valueUSLRange = worksheetDo_ThisMonth.Range.FromLTRB(columnLSL + 1, reportModel.monthDataStartRowIndex + 1, columnLSL + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameUSLRange, agumentRage, valueUSLRange);

            //chartIA.Series[0].ChangeType(ChartType.ScatterLineMarkers);

            chartIA.Legend.Position = LegendPosition.Bottom;
            chartIA.Title.Visible = true;
            chartIA.Title.SetValue(reportModel.goodsName);








        }
        private void DoDecorate(DoMonthReportModel reportModel, DateTime startDate, DateTime endDate)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["2)DO"];

            //加边框
            Range range = worksheetDoView.Range.FromLTRB(0, reportModel.viewStartRowIndex, 13, reportModel.viewStartRowIndex + 15);
            range.SetInsideBorders(Color.Black, BorderLineStyle.Dashed);
            range.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
            range.Font.Bold = true;


            Formatting rangeFormatting1 = range.BeginUpdateFormatting();
            rangeFormatting1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            range.EndUpdateFormatting(rangeFormatting1);


            //一年的数据加背景颜色
            Range rangeYear = worksheetDoView.Range.FromLTRB(2, reportModel.viewStartRowIndex + 10, 13, reportModel.viewStartRowIndex + 15);

            Formatting rangeFormatting2 = rangeYear.BeginUpdateFormatting();
            rangeFormatting2.Fill.BackgroundColor = Color.FromArgb(204, 255, 204);
            rangeFormatting2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            rangeYear.EndUpdateFormatting(rangeFormatting2);

            worksheetDoView[reportModel.viewStartRowIndex + 5, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();

            worksheetDoView[reportModel.viewStartRowIndex + 11, 2].Value = new DateTime(startDate.Year, 01, 01).ToShortDateString() + "--" + endDate.ToShortDateString();
        }

        #endregion

        #region 合成样报告相关方法
        private void InitialCompReport(DateTime startDate, DateTime endDate)
        {
            int startRowIndex = 1;
            int startRowIndexMonth = 0;
            int startRowIndexYear = 0;

            List<Good> goodsSemiList = db.Goods.Where(m => m.GoodsTypeID == CommonData.GoodsType_Production_ID).ToList();
            List<DoMonthReportModel> DoData = new List<DoMonthReportModel>();
            //string sql = "SELECT [Project52].[GoodsName] AS [GoodsName], [Project52].[SamplingPlaceName] AS [SamplingPlaceName], [Project52].[ProductionLineName] AS [ProductionLineName], [Project52].[ProductionGroupName] AS [ProductionGroupName], [Project52].[SendDate] AS [SendDate], [Project52].[Remark] AS [Remark], [Project52].[EmpName] AS [EmpName], CONVERT(float, [Project52].[C2]) AS [IA], CONVERT(float,[Project52].[C3] )AS [DBP], CONVERT(float, [Project52].[C4] )AS [IPH(AVG)], CONVERT(float, [Project52].[C5] )AS [IPH(Gigh)], CONVERT(float,[Project52].[C6] )AS [IPH(Low)], CONVERT(float, [Project52].[C7]) AS [Fines], CONVERT(float, [Project52].[C8]) AS [HL], CONVERT(float, [Project52].[C9]) AS [Sieve Residue(#35)], CONVERT(float,[Project52].[C10]) AS [Sieve Residue(#100)], CONVERT(float,[Project52].[C11]) AS [Sieve Residue(#325)], CONVERT(float,[Project52].[C12]) AS [LT], CONVERT(float,[Project52].[C13]) AS [PD], CONVERT(float,[Project52].[C14]) AS [PH], CONVERT(float,[Project52].[C15]) AS [Tint], CONVERT(float,[Project52].[C16] )AS [CDBP], CONVERT(float,[Project52].[C17]) AS [N2SA], CONVERT(float,[Project52].[C18] )AS [Ash] FROM ( SELECT [Project51].[SendDate] AS [SendDate], [Project51].[Remark] AS [Remark], [Project51].[GoodsName] AS [GoodsName], [Project51].[SamplingPlaceName] AS [SamplingPlaceName], [Project51].[ProductionLineName] AS [ProductionLineName], [Project51].[ProductionGroupName] AS [ProductionGroupName], [Project51].[EmpName] AS [EmpName], 1 AS [C1], [Project51].[C1] AS [C2], [Project51].[C2] AS [C3], [Project51].[C3] AS [C4], [Project51].[C4] AS [C5], [Project51].[C5] AS [C6], [Project51].[C6] AS [C7], [Project51].[C7] AS [C8], [Project51].[C8] AS [C9], [Project51].[C9] AS [C10], [Project51].[C10] AS [C11], [Project51].[C11] AS [C12], [Project51].[C12] AS [C13], [Project51].[C13] AS [C14], [Project51].[C14] AS [C15], [Project51].[C15] AS [C16], [Project51].[C16] AS [C17], [Project51].[C17] AS [C18] FROM ( SELECT [Project49].[ReportSemiID] AS [ReportSemiID], [Project49].[SendDate] AS [SendDate], [Project49].[Remark] AS [Remark], [Project49].[GoodsName] AS [GoodsName], [Project49].[SamplingPlaceName] AS [SamplingPlaceName], [Project49].[ProductionLineName] AS [ProductionLineName], [Project49].[ProductionGroupName] AS [ProductionGroupName], [Project49].[EmpName] AS [EmpName], [Project49].[C1] AS [C1], [Project49].[C2] AS [C2], [Project49].[C3] AS [C3], [Project49].[C4] AS [C4], [Project49].[C5] AS [C5], [Project49].[C6] AS [C6], [Project49].[C7] AS [C7], [Project49].[C8] AS [C8], [Project49].[C9] AS [C9], [Project49].[C10] AS [C10], [Project49].[C11] AS [C11], [Project49].[C12] AS [C12], [Project49].[C13] AS [C13], [Project49].[C14] AS [C14], [Project49].[C15] AS [C15], [Project49].[C16] AS [C16], (SELECT TOP (1) [Extent23].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent23] WHERE ([Project49].[ReportSemiID] = [Extent23].[ReportSemiID]) AND ('27' = [Extent23].[TestItemID])) AS [C17] FROM ( SELECT [Project48].[ReportSemiID] AS [ReportSemiID], [Project48].[SendDate] AS [SendDate], [Project48].[Remark] AS [Remark], [Project48].[GoodsName] AS [GoodsName], [Project48].[SamplingPlaceName] AS [SamplingPlaceName], [Project48].[ProductionLineName] AS [ProductionLineName], [Project48].[ProductionGroupName] AS [ProductionGroupName], [Project48].[EmpName] AS [EmpName], [Project48].[C1] AS [C1], [Project48].[C2] AS [C2], [Project48].[C3] AS [C3], [Project48].[C4] AS [C4], [Project48].[C5] AS [C5], [Project48].[C6] AS [C6], [Project48].[C7] AS [C7], [Project48].[C8] AS [C8], [Project48].[C9] AS [C9], [Project48].[C10] AS [C10], [Project48].[C11] AS [C11], [Project48].[C12] AS [C12], [Project48].[C13] AS [C13], [Project48].[C14] AS [C14], [Project48].[C15] AS [C15], [Project48].[C16] AS [C16] FROM ( SELECT [Project46].[ReportSemiID] AS [ReportSemiID], [Project46].[SendDate] AS [SendDate], [Project46].[Remark] AS [Remark], [Project46].[GoodsName] AS [GoodsName], [Project46].[SamplingPlaceName] AS [SamplingPlaceName], [Project46].[ProductionLineName] AS [ProductionLineName], [Project46].[ProductionGroupName] AS [ProductionGroupName], [Project46].[EmpName] AS [EmpName], [Project46].[C1] AS [C1], [Project46].[C2] AS [C2], [Project46].[C3] AS [C3], [Project46].[C4] AS [C4], [Project46].[C5] AS [C5], [Project46].[C6] AS [C6], [Project46].[C7] AS [C7], [Project46].[C8] AS [C8], [Project46].[C9] AS [C9], [Project46].[C10] AS [C10], [Project46].[C11] AS [C11], [Project46].[C12] AS [C12], [Project46].[C13] AS [C13], [Project46].[C14] AS [C14], [Project46].[C15] AS [C15], (SELECT TOP (1) [Extent22].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent22] WHERE ([Project46].[ReportSemiID] = [Extent22].[ReportSemiID]) AND ('28' = [Extent22].[TestItemID])) AS [C16] FROM ( SELECT [Project45].[ReportSemiID] AS [ReportSemiID], [Project45].[SendDate] AS [SendDate], [Project45].[Remark] AS [Remark], [Project45].[GoodsName] AS [GoodsName], [Project45].[SamplingPlaceName] AS [SamplingPlaceName], [Project45].[ProductionLineName] AS [ProductionLineName], [Project45].[ProductionGroupName] AS [ProductionGroupName], [Project45].[EmpName] AS [EmpName], [Project45].[C1] AS [C1], [Project45].[C2] AS [C2], [Project45].[C3] AS [C3], [Project45].[C4] AS [C4], [Project45].[C5] AS [C5], [Project45].[C6] AS [C6], [Project45].[C7] AS [C7], [Project45].[C8] AS [C8], [Project45].[C9] AS [C9], [Project45].[C10] AS [C10], [Project45].[C11] AS [C11], [Project45].[C12] AS [C12], [Project45].[C13] AS [C13], [Project45].[C14] AS [C14], [Project45].[C15] AS [C15] FROM ( SELECT [Project43].[ReportSemiID] AS [ReportSemiID], [Project43].[SendDate] AS [SendDate], [Project43].[Remark] AS [Remark], [Project43].[GoodsName] AS [GoodsName], [Project43].[SamplingPlaceName] AS [SamplingPlaceName], [Project43].[ProductionLineName] AS [ProductionLineName], [Project43].[ProductionGroupName] AS [ProductionGroupName], [Project43].[EmpName] AS [EmpName], [Project43].[C1] AS [C1], [Project43].[C2] AS [C2], [Project43].[C3] AS [C3], [Project43].[C4] AS [C4], [Project43].[C5] AS [C5], [Project43].[C6] AS [C6], [Project43].[C7] AS [C7], [Project43].[C8] AS [C8], [Project43].[C9] AS [C9], [Project43].[C10] AS [C10], [Project43].[C11] AS [C11], [Project43].[C12] AS [C12], [Project43].[C13] AS [C13], [Project43].[C14] AS [C14], (SELECT TOP (1) [Extent21].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent21] WHERE ([Project43].[ReportSemiID] = [Extent21].[ReportSemiID]) AND ('26' = [Extent21].[TestItemID])) AS [C15] FROM ( SELECT [Project42].[ReportSemiID] AS [ReportSemiID], [Project42].[SendDate] AS [SendDate], [Project42].[Remark] AS [Remark], [Project42].[GoodsName] AS [GoodsName], [Project42].[SamplingPlaceName] AS [SamplingPlaceName], [Project42].[ProductionLineName] AS [ProductionLineName], [Project42].[ProductionGroupName] AS [ProductionGroupName], [Project42].[EmpName] AS [EmpName], [Project42].[C1] AS [C1], [Project42].[C2] AS [C2], [Project42].[C3] AS [C3], [Project42].[C4] AS [C4], [Project42].[C5] AS [C5], [Project42].[C6] AS [C6], [Project42].[C7] AS [C7], [Project42].[C8] AS [C8], [Project42].[C9] AS [C9], [Project42].[C10] AS [C10], [Project42].[C11] AS [C11], [Project42].[C12] AS [C12], [Project42].[C13] AS [C13], [Project42].[C14] AS [C14] FROM ( SELECT [Project40].[ReportSemiID] AS [ReportSemiID], [Project40].[SendDate] AS [SendDate], [Project40].[Remark] AS [Remark], [Project40].[GoodsName] AS [GoodsName], [Project40].[SamplingPlaceName] AS [SamplingPlaceName], [Project40].[ProductionLineName] AS [ProductionLineName], [Project40].[ProductionGroupName] AS [ProductionGroupName], [Project40].[EmpName] AS [EmpName], [Project40].[C1] AS [C1], [Project40].[C2] AS [C2], [Project40].[C3] AS [C3], [Project40].[C4] AS [C4], [Project40].[C5] AS [C5], [Project40].[C6] AS [C6], [Project40].[C7] AS [C7], [Project40].[C8] AS [C8], [Project40].[C9] AS [C9], [Project40].[C10] AS [C10], [Project40].[C11] AS [C11], [Project40].[C12] AS [C12], [Project40].[C13] AS [C13], (SELECT TOP (1) [Extent20].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent20] WHERE ([Project40].[ReportSemiID] = [Extent20].[ReportSemiID]) AND ('25' = [Extent20].[TestItemID])) AS [C14] FROM ( SELECT [Project39].[ReportSemiID] AS [ReportSemiID], [Project39].[SendDate] AS [SendDate], [Project39].[Remark] AS [Remark], [Project39].[GoodsName] AS [GoodsName], [Project39].[SamplingPlaceName] AS [SamplingPlaceName], [Project39].[ProductionLineName] AS [ProductionLineName], [Project39].[ProductionGroupName] AS [ProductionGroupName], [Project39].[EmpName] AS [EmpName], [Project39].[C1] AS [C1], [Project39].[C2] AS [C2], [Project39].[C3] AS [C3], [Project39].[C4] AS [C4], [Project39].[C5] AS [C5], [Project39].[C6] AS [C6], [Project39].[C7] AS [C7], [Project39].[C8] AS [C8], [Project39].[C9] AS [C9], [Project39].[C10] AS [C10], [Project39].[C11] AS [C11], [Project39].[C12] AS [C12], [Project39].[C13] AS [C13] FROM ( SELECT [Project37].[ReportSemiID] AS [ReportSemiID], [Project37].[SendDate] AS [SendDate], [Project37].[Remark] AS [Remark], [Project37].[GoodsName] AS [GoodsName], [Project37].[SamplingPlaceName] AS [SamplingPlaceName], [Project37].[ProductionLineName] AS [ProductionLineName], [Project37].[ProductionGroupName] AS [ProductionGroupName], [Project37].[EmpName] AS [EmpName], [Project37].[C1] AS [C1], [Project37].[C2] AS [C2], [Project37].[C3] AS [C3], [Project37].[C4] AS [C4], [Project37].[C5] AS [C5], [Project37].[C6] AS [C6], [Project37].[C7] AS [C7], [Project37].[C8] AS [C8], [Project37].[C9] AS [C9], [Project37].[C10] AS [C10], [Project37].[C11] AS [C11], [Project37].[C12] AS [C12], (SELECT TOP (1) [Extent19].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent19] WHERE ([Project37].[ReportSemiID] = [Extent19].[ReportSemiID]) AND ('17' = [Extent19].[TestItemID])) AS [C13] FROM ( SELECT [Project36].[ReportSemiID] AS [ReportSemiID], [Project36].[SendDate] AS [SendDate], [Project36].[Remark] AS [Remark], [Project36].[GoodsName] AS [GoodsName], [Project36].[SamplingPlaceName] AS [SamplingPlaceName], [Project36].[ProductionLineName] AS [ProductionLineName], [Project36].[ProductionGroupName] AS [ProductionGroupName], [Project36].[EmpName] AS [EmpName], [Project36].[C1] AS [C1], [Project36].[C2] AS [C2], [Project36].[C3] AS [C3], [Project36].[C4] AS [C4], [Project36].[C5] AS [C5], [Project36].[C6] AS [C6], [Project36].[C7] AS [C7], [Project36].[C8] AS [C8], [Project36].[C9] AS [C9], [Project36].[C10] AS [C10], [Project36].[C11] AS [C11], [Project36].[C12] AS [C12] FROM ( SELECT [Project34].[ReportSemiID] AS [ReportSemiID], [Project34].[SendDate] AS [SendDate], [Project34].[Remark] AS [Remark], [Project34].[GoodsName] AS [GoodsName], [Project34].[SamplingPlaceName] AS [SamplingPlaceName], [Project34].[ProductionLineName] AS [ProductionLineName], [Project34].[ProductionGroupName] AS [ProductionGroupName], [Project34].[EmpName] AS [EmpName], [Project34].[C1] AS [C1], [Project34].[C2] AS [C2], [Project34].[C3] AS [C3], [Project34].[C4] AS [C4], [Project34].[C5] AS [C5], [Project34].[C6] AS [C6], [Project34].[C7] AS [C7], [Project34].[C8] AS [C8], [Project34].[C9] AS [C9], [Project34].[C10] AS [C10], [Project34].[C11] AS [C11], (SELECT TOP (1) [Extent18].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent18] WHERE ([Project34].[ReportSemiID] = [Extent18].[ReportSemiID]) AND ('16' = [Extent18].[TestItemID])) AS [C12] FROM ( SELECT [Project33].[ReportSemiID] AS [ReportSemiID], [Project33].[SendDate] AS [SendDate], [Project33].[Remark] AS [Remark], [Project33].[GoodsName] AS [GoodsName], [Project33].[SamplingPlaceName] AS [SamplingPlaceName], [Project33].[ProductionLineName] AS [ProductionLineName], [Project33].[ProductionGroupName] AS [ProductionGroupName], [Project33].[EmpName] AS [EmpName], [Project33].[C1] AS [C1], [Project33].[C2] AS [C2], [Project33].[C3] AS [C3], [Project33].[C4] AS [C4], [Project33].[C5] AS [C5], [Project33].[C6] AS [C6], [Project33].[C7] AS [C7], [Project33].[C8] AS [C8], [Project33].[C9] AS [C9], [Project33].[C10] AS [C10], [Project33].[C11] AS [C11] FROM ( SELECT [Project31].[ReportSemiID] AS [ReportSemiID], [Project31].[SendDate] AS [SendDate], [Project31].[Remark] AS [Remark], [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[ProductionLineName] AS [ProductionLineName], [Project31].[ProductionGroupName] AS [ProductionGroupName], [Project31].[EmpName] AS [EmpName], [Project31].[C1] AS [C1], [Project31].[C2] AS [C2], [Project31].[C3] AS [C3], [Project31].[C4] AS [C4], [Project31].[C5] AS [C5], [Project31].[C6] AS [C6], [Project31].[C7] AS [C7], [Project31].[C8] AS [C8], [Project31].[C9] AS [C9], [Project31].[C10] AS [C10], (SELECT TOP (1) [Extent17].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent17] WHERE ([Project31].[ReportSemiID] = [Extent17].[ReportSemiID]) AND ('15' = [Extent17].[TestItemID])) AS [C11] FROM ( SELECT [Project30].[ReportSemiID] AS [ReportSemiID], [Project30].[SendDate] AS [SendDate], [Project30].[Remark] AS [Remark], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[ProductionLineName] AS [ProductionLineName], [Project30].[ProductionGroupName] AS [ProductionGroupName], [Project30].[EmpName] AS [EmpName], [Project30].[C1] AS [C1], [Project30].[C2] AS [C2], [Project30].[C3] AS [C3], [Project30].[C4] AS [C4], [Project30].[C5] AS [C5], [Project30].[C6] AS [C6], [Project30].[C7] AS [C7], [Project30].[C8] AS [C8], [Project30].[C9] AS [C9], [Project30].[C10] AS [C10] FROM ( SELECT [Project28].[ReportSemiID] AS [ReportSemiID], [Project28].[SendDate] AS [SendDate], [Project28].[Remark] AS [Remark], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[ProductionLineName] AS [ProductionLineName], [Project28].[ProductionGroupName] AS [ProductionGroupName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent16] WHERE ([Project28].[ReportSemiID] = [Extent16].[ReportSemiID]) AND ('14' = [Extent16].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportSemiID] AS [ReportSemiID], [Project27].[SendDate] AS [SendDate], [Project27].[Remark] AS [Remark], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[ProductionLineName] AS [ProductionLineName], [Project27].[ProductionGroupName] AS [ProductionGroupName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportSemiID] AS [ReportSemiID], [Project25].[SendDate] AS [SendDate], [Project25].[Remark] AS [Remark], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[ProductionLineName] AS [ProductionLineName], [Project25].[ProductionGroupName] AS [ProductionGroupName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent15] WHERE ([Project25].[ReportSemiID] = [Extent15].[ReportSemiID]) AND ('13' = [Extent15].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportSemiID] AS [ReportSemiID], [Project24].[SendDate] AS [SendDate], [Project24].[Remark] AS [Remark], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[ProductionLineName] AS [ProductionLineName], [Project24].[ProductionGroupName] AS [ProductionGroupName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportSemiID] AS [ReportSemiID], [Project22].[SendDate] AS [SendDate], [Project22].[Remark] AS [Remark], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[ProductionLineName] AS [ProductionLineName], [Project22].[ProductionGroupName] AS [ProductionGroupName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent14] WHERE ([Project22].[ReportSemiID] = [Extent14].[ReportSemiID]) AND ('12' = [Extent14].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportSemiID] AS [ReportSemiID], [Project21].[SendDate] AS [SendDate], [Project21].[Remark] AS [Remark], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[ProductionLineName] AS [ProductionLineName], [Project21].[ProductionGroupName] AS [ProductionGroupName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportSemiID] AS [ReportSemiID], [Project19].[SendDate] AS [SendDate], [Project19].[Remark] AS [Remark], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[ProductionLineName] AS [ProductionLineName], [Project19].[ProductionGroupName] AS [ProductionGroupName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent13] WHERE ([Project19].[ReportSemiID] = [Extent13].[ReportSemiID]) AND ('10' = [Extent13].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportSemiID] AS [ReportSemiID], [Project18].[SendDate] AS [SendDate], [Project18].[Remark] AS [Remark], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[ProductionLineName] AS [ProductionLineName], [Project18].[ProductionGroupName] AS [ProductionGroupName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportSemiID] AS [ReportSemiID], [Project16].[SendDate] AS [SendDate], [Project16].[Remark] AS [Remark], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[ProductionLineName] AS [ProductionLineName], [Project16].[ProductionGroupName] AS [ProductionGroupName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent12] WHERE ([Project16].[ReportSemiID] = [Extent12].[ReportSemiID]) AND ('9' = [Extent12].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportSemiID] AS [ReportSemiID], [Project15].[SendDate] AS [SendDate], [Project15].[Remark] AS [Remark], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[ProductionLineName] AS [ProductionLineName], [Project15].[ProductionGroupName] AS [ProductionGroupName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportSemiID] AS [ReportSemiID], [Project13].[SendDate] AS [SendDate], [Project13].[Remark] AS [Remark], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[ProductionLineName] AS [ProductionLineName], [Project13].[ProductionGroupName] AS [ProductionGroupName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent11] WHERE ([Project13].[ReportSemiID] = [Extent11].[ReportSemiID]) AND ('30' = [Extent11].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportSemiID] AS [ReportSemiID], [Project12].[SendDate] AS [SendDate], [Project12].[Remark] AS [Remark], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[ProductionLineName] AS [ProductionLineName], [Project12].[ProductionGroupName] AS [ProductionGroupName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportSemiID] AS [ReportSemiID], [Project10].[SendDate] AS [SendDate], [Project10].[Remark] AS [Remark], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[ProductionLineName] AS [ProductionLineName], [Project10].[ProductionGroupName] AS [ProductionGroupName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent10] WHERE ([Project10].[ReportSemiID] = [Extent10].[ReportSemiID]) AND ('8' = [Extent10].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportSemiID] AS [ReportSemiID], [Project9].[SendDate] AS [SendDate], [Project9].[Remark] AS [Remark], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[ProductionLineName] AS [ProductionLineName], [Project9].[ProductionGroupName] AS [ProductionGroupName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportSemiID] AS [ReportSemiID], [Project7].[SendDate] AS [SendDate], [Project7].[Remark] AS [Remark], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[ProductionLineName] AS [ProductionLineName], [Project7].[ProductionGroupName] AS [ProductionGroupName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent9] WHERE ([Project7].[ReportSemiID] = [Extent9].[ReportSemiID]) AND ('46' = [Extent9].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportSemiID] AS [ReportSemiID], [Project6].[SendDate] AS [SendDate], [Project6].[Remark] AS [Remark], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[ProductionLineName] AS [ProductionLineName], [Project6].[ProductionGroupName] AS [ProductionGroupName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportSemiID] AS [ReportSemiID], [Project4].[SendDate] AS [SendDate], [Project4].[Remark] AS [Remark], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[ProductionLineName] AS [ProductionLineName], [Project4].[ProductionGroupName] AS [ProductionGroupName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent8] WHERE ([Project4].[ReportSemiID] = [Extent8].[ReportSemiID]) AND ('7' = [Extent8].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportSemiID] AS [ReportSemiID], [Project3].[SendDate] AS [SendDate], [Project3].[Remark] AS [Remark], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[ProductionLineName] AS [ProductionLineName], [Project3].[ProductionGroupName] AS [ProductionGroupName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportSemiID] AS [ReportSemiID], [Project1].[SendDate] AS [SendDate], [Project1].[Remark] AS [Remark], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[ProductionLineName] AS [ProductionLineName], [Project1].[ProductionGroupName] AS [ProductionGroupName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent7] WHERE ([Project1].[ReportSemiID] = [Extent7].[ReportSemiID]) AND ('1' = [Extent7].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportSemiID] AS [ReportSemiID], [Filter1].[SendDate] AS [SendDate], [Filter1].[Remark1] AS [Remark], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Filter1].[ProductionLineName] AS [ProductionLineName], [Filter1].[ProductionGroupName] AS [ProductionGroupName], [Extent6].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportSemiID] AS [ReportSemiID], [Extent1].[SendDate] AS [SendDate], [Extent1].[Remark] AS [Remark1], [Extent1].[LoginUserID] AS [LoginUserID], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[ProductionLineName] AS [ProductionLineName], [Extent5].[ProductionGroupName] AS [ProductionGroupName] FROM [dbo].[ReportSemis] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaces] AS [Extent3] ON [Extent1].[SamplingPlaceID] = [Extent3].[SamplingPlaceID] INNER JOIN [dbo].[ProductionLines] AS [Extent4] ON [Extent1].[ProductionLineID] = [Extent4].[ProductionLineID] INNER JOIN [dbo].[ProductionGroups] AS [Extent5] ON [Extent1].[ProductionGroupID] = [Extent5].[ProductionGroupID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('2' = [Extent1].[SamplingPlaceID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent6] ON [Filter1].[LoginUserID] = [Extent6].[LoginUserID] WHERE ([Filter1].[SendDate] <= @EndDate) AND ([Filter1].[SendDate] >= @StartDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ) AS [Project33] ) AS [Project34] ) AS [Project36] ) AS [Project37] ) AS [Project39] ) AS [Project40] ) AS [Project42] ) AS [Project43] ) AS [Project45] ) AS [Project46] ) AS [Project48] ) AS [Project49] ) AS [Project51] ) AS [Project52] ORDER BY [Project52].[SendDate] ASC";
            string sql = "SELECT [Project52].[GoodsName] AS [GoodsName], [Project52].[SamplingPlaceName] AS [SamplingPlaceName], [Project52].[ProductionLineName] AS [ProductionLineName], [Project52].[ProductionGroupName] AS [ProductionGroupName], [Project52].[SendDate] AS [SendDate], [Project52].[Remark] AS [Remark], [Project52].[EmpName] AS [EmpName], CASE [Project52].[C2] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C2] ) END AS [IA], CASE [Project52].[C3] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C3] ) END AS [DBP], CASE [Project52].[C4] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C4] ) END AS [IPH(AVG)], CASE [Project52].[C5] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C5] ) END AS [IPH(Gigh)], CASE [Project52].[C6] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C6] ) END AS [IPH(Low)], CASE [Project52].[C7] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C7] ) END AS [Fines], CASE [Project52].[C8] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C8] ) END AS [HL], CASE [Project52].[C9] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C9] ) END AS [Sieve Residue(#35)], CASE [Project52].[C10] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C10]) END AS [Sieve Residue(#100)], CASE [Project52].[C11] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C11]) END AS [Sieve Residue(#325)], CASE [Project52].[C12] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C12]) END AS [LT], CASE [Project52].[C13] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C13]) END AS [PD], CASE [Project52].[C14] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C14]) END AS [PH], CASE [Project52].[C15] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C15]) END AS [Tint], CASE [Project52].[C16] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C16]) END AS [CDBP], CASE [Project52].[C17] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C17]) END AS [N2SA], CASE [Project52].[C18] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C18]) END AS [Ash] FROM ( SELECT [Project51].[SendDate] AS [SendDate], [Project51].[Remark] AS [Remark], [Project51].[GoodsName] AS [GoodsName], [Project51].[SamplingPlaceName] AS [SamplingPlaceName], [Project51].[ProductionLineName] AS [ProductionLineName], [Project51].[ProductionGroupName] AS [ProductionGroupName], [Project51].[EmpName] AS [EmpName], 1 AS [C1], [Project51].[C1] AS [C2], [Project51].[C2] AS [C3], [Project51].[C3] AS [C4], [Project51].[C4] AS [C5], [Project51].[C5] AS [C6], [Project51].[C6] AS [C7], [Project51].[C7] AS [C8], [Project51].[C8] AS [C9], [Project51].[C9] AS [C10], [Project51].[C10] AS [C11], [Project51].[C11] AS [C12], [Project51].[C12] AS [C13], [Project51].[C13] AS [C14], [Project51].[C14] AS [C15], [Project51].[C15] AS [C16], [Project51].[C16] AS [C17], [Project51].[C17] AS [C18] FROM ( SELECT [Project49].[ReportSemiID] AS [ReportSemiID], [Project49].[SendDate] AS [SendDate], [Project49].[Remark] AS [Remark], [Project49].[GoodsName] AS [GoodsName], [Project49].[SamplingPlaceName] AS [SamplingPlaceName], [Project49].[ProductionLineName] AS [ProductionLineName], [Project49].[ProductionGroupName] AS [ProductionGroupName], [Project49].[EmpName] AS [EmpName], [Project49].[C1] AS [C1], [Project49].[C2] AS [C2], [Project49].[C3] AS [C3], [Project49].[C4] AS [C4], [Project49].[C5] AS [C5], [Project49].[C6] AS [C6], [Project49].[C7] AS [C7], [Project49].[C8] AS [C8], [Project49].[C9] AS [C9], [Project49].[C10] AS [C10], [Project49].[C11] AS [C11], [Project49].[C12] AS [C12], [Project49].[C13] AS [C13], [Project49].[C14] AS [C14], [Project49].[C15] AS [C15], [Project49].[C16] AS [C16], (SELECT TOP (1) [Extent23].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent23] WHERE ([Project49].[ReportSemiID] = [Extent23].[ReportSemiID]) AND ('27' = [Extent23].[TestItemID])) AS [C17] FROM ( SELECT [Project48].[ReportSemiID] AS [ReportSemiID], [Project48].[SendDate] AS [SendDate], [Project48].[Remark] AS [Remark], [Project48].[GoodsName] AS [GoodsName], [Project48].[SamplingPlaceName] AS [SamplingPlaceName], [Project48].[ProductionLineName] AS [ProductionLineName], [Project48].[ProductionGroupName] AS [ProductionGroupName], [Project48].[EmpName] AS [EmpName], [Project48].[C1] AS [C1], [Project48].[C2] AS [C2], [Project48].[C3] AS [C3], [Project48].[C4] AS [C4], [Project48].[C5] AS [C5], [Project48].[C6] AS [C6], [Project48].[C7] AS [C7], [Project48].[C8] AS [C8], [Project48].[C9] AS [C9], [Project48].[C10] AS [C10], [Project48].[C11] AS [C11], [Project48].[C12] AS [C12], [Project48].[C13] AS [C13], [Project48].[C14] AS [C14], [Project48].[C15] AS [C15], [Project48].[C16] AS [C16] FROM ( SELECT [Project46].[ReportSemiID] AS [ReportSemiID], [Project46].[SendDate] AS [SendDate], [Project46].[Remark] AS [Remark], [Project46].[GoodsName] AS [GoodsName], [Project46].[SamplingPlaceName] AS [SamplingPlaceName], [Project46].[ProductionLineName] AS [ProductionLineName], [Project46].[ProductionGroupName] AS [ProductionGroupName], [Project46].[EmpName] AS [EmpName], [Project46].[C1] AS [C1], [Project46].[C2] AS [C2], [Project46].[C3] AS [C3], [Project46].[C4] AS [C4], [Project46].[C5] AS [C5], [Project46].[C6] AS [C6], [Project46].[C7] AS [C7], [Project46].[C8] AS [C8], [Project46].[C9] AS [C9], [Project46].[C10] AS [C10], [Project46].[C11] AS [C11], [Project46].[C12] AS [C12], [Project46].[C13] AS [C13], [Project46].[C14] AS [C14], [Project46].[C15] AS [C15], (SELECT TOP (1) [Extent22].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent22] WHERE ([Project46].[ReportSemiID] = [Extent22].[ReportSemiID]) AND ('28' = [Extent22].[TestItemID])) AS [C16] FROM ( SELECT [Project45].[ReportSemiID] AS [ReportSemiID], [Project45].[SendDate] AS [SendDate], [Project45].[Remark] AS [Remark], [Project45].[GoodsName] AS [GoodsName], [Project45].[SamplingPlaceName] AS [SamplingPlaceName], [Project45].[ProductionLineName] AS [ProductionLineName], [Project45].[ProductionGroupName] AS [ProductionGroupName], [Project45].[EmpName] AS [EmpName], [Project45].[C1] AS [C1], [Project45].[C2] AS [C2], [Project45].[C3] AS [C3], [Project45].[C4] AS [C4], [Project45].[C5] AS [C5], [Project45].[C6] AS [C6], [Project45].[C7] AS [C7], [Project45].[C8] AS [C8], [Project45].[C9] AS [C9], [Project45].[C10] AS [C10], [Project45].[C11] AS [C11], [Project45].[C12] AS [C12], [Project45].[C13] AS [C13], [Project45].[C14] AS [C14], [Project45].[C15] AS [C15] FROM ( SELECT [Project43].[ReportSemiID] AS [ReportSemiID], [Project43].[SendDate] AS [SendDate], [Project43].[Remark] AS [Remark], [Project43].[GoodsName] AS [GoodsName], [Project43].[SamplingPlaceName] AS [SamplingPlaceName], [Project43].[ProductionLineName] AS [ProductionLineName], [Project43].[ProductionGroupName] AS [ProductionGroupName], [Project43].[EmpName] AS [EmpName], [Project43].[C1] AS [C1], [Project43].[C2] AS [C2], [Project43].[C3] AS [C3], [Project43].[C4] AS [C4], [Project43].[C5] AS [C5], [Project43].[C6] AS [C6], [Project43].[C7] AS [C7], [Project43].[C8] AS [C8], [Project43].[C9] AS [C9], [Project43].[C10] AS [C10], [Project43].[C11] AS [C11], [Project43].[C12] AS [C12], [Project43].[C13] AS [C13], [Project43].[C14] AS [C14], (SELECT TOP (1) [Extent21].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent21] WHERE ([Project43].[ReportSemiID] = [Extent21].[ReportSemiID]) AND ('26' = [Extent21].[TestItemID])) AS [C15] FROM ( SELECT [Project42].[ReportSemiID] AS [ReportSemiID], [Project42].[SendDate] AS [SendDate], [Project42].[Remark] AS [Remark], [Project42].[GoodsName] AS [GoodsName], [Project42].[SamplingPlaceName] AS [SamplingPlaceName], [Project42].[ProductionLineName] AS [ProductionLineName], [Project42].[ProductionGroupName] AS [ProductionGroupName], [Project42].[EmpName] AS [EmpName], [Project42].[C1] AS [C1], [Project42].[C2] AS [C2], [Project42].[C3] AS [C3], [Project42].[C4] AS [C4], [Project42].[C5] AS [C5], [Project42].[C6] AS [C6], [Project42].[C7] AS [C7], [Project42].[C8] AS [C8], [Project42].[C9] AS [C9], [Project42].[C10] AS [C10], [Project42].[C11] AS [C11], [Project42].[C12] AS [C12], [Project42].[C13] AS [C13], [Project42].[C14] AS [C14] FROM ( SELECT [Project40].[ReportSemiID] AS [ReportSemiID], [Project40].[SendDate] AS [SendDate], [Project40].[Remark] AS [Remark], [Project40].[GoodsName] AS [GoodsName], [Project40].[SamplingPlaceName] AS [SamplingPlaceName], [Project40].[ProductionLineName] AS [ProductionLineName], [Project40].[ProductionGroupName] AS [ProductionGroupName], [Project40].[EmpName] AS [EmpName], [Project40].[C1] AS [C1], [Project40].[C2] AS [C2], [Project40].[C3] AS [C3], [Project40].[C4] AS [C4], [Project40].[C5] AS [C5], [Project40].[C6] AS [C6], [Project40].[C7] AS [C7], [Project40].[C8] AS [C8], [Project40].[C9] AS [C9], [Project40].[C10] AS [C10], [Project40].[C11] AS [C11], [Project40].[C12] AS [C12], [Project40].[C13] AS [C13], (SELECT TOP (1) [Extent20].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent20] WHERE ([Project40].[ReportSemiID] = [Extent20].[ReportSemiID]) AND ('25' = [Extent20].[TestItemID])) AS [C14] FROM ( SELECT [Project39].[ReportSemiID] AS [ReportSemiID], [Project39].[SendDate] AS [SendDate], [Project39].[Remark] AS [Remark], [Project39].[GoodsName] AS [GoodsName], [Project39].[SamplingPlaceName] AS [SamplingPlaceName], [Project39].[ProductionLineName] AS [ProductionLineName], [Project39].[ProductionGroupName] AS [ProductionGroupName], [Project39].[EmpName] AS [EmpName], [Project39].[C1] AS [C1], [Project39].[C2] AS [C2], [Project39].[C3] AS [C3], [Project39].[C4] AS [C4], [Project39].[C5] AS [C5], [Project39].[C6] AS [C6], [Project39].[C7] AS [C7], [Project39].[C8] AS [C8], [Project39].[C9] AS [C9], [Project39].[C10] AS [C10], [Project39].[C11] AS [C11], [Project39].[C12] AS [C12], [Project39].[C13] AS [C13] FROM ( SELECT [Project37].[ReportSemiID] AS [ReportSemiID], [Project37].[SendDate] AS [SendDate], [Project37].[Remark] AS [Remark], [Project37].[GoodsName] AS [GoodsName], [Project37].[SamplingPlaceName] AS [SamplingPlaceName], [Project37].[ProductionLineName] AS [ProductionLineName], [Project37].[ProductionGroupName] AS [ProductionGroupName], [Project37].[EmpName] AS [EmpName], [Project37].[C1] AS [C1], [Project37].[C2] AS [C2], [Project37].[C3] AS [C3], [Project37].[C4] AS [C4], [Project37].[C5] AS [C5], [Project37].[C6] AS [C6], [Project37].[C7] AS [C7], [Project37].[C8] AS [C8], [Project37].[C9] AS [C9], [Project37].[C10] AS [C10], [Project37].[C11] AS [C11], [Project37].[C12] AS [C12], (SELECT TOP (1) [Extent19].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent19] WHERE ([Project37].[ReportSemiID] = [Extent19].[ReportSemiID]) AND ('17' = [Extent19].[TestItemID])) AS [C13] FROM ( SELECT [Project36].[ReportSemiID] AS [ReportSemiID], [Project36].[SendDate] AS [SendDate], [Project36].[Remark] AS [Remark], [Project36].[GoodsName] AS [GoodsName], [Project36].[SamplingPlaceName] AS [SamplingPlaceName], [Project36].[ProductionLineName] AS [ProductionLineName], [Project36].[ProductionGroupName] AS [ProductionGroupName], [Project36].[EmpName] AS [EmpName], [Project36].[C1] AS [C1], [Project36].[C2] AS [C2], [Project36].[C3] AS [C3], [Project36].[C4] AS [C4], [Project36].[C5] AS [C5], [Project36].[C6] AS [C6], [Project36].[C7] AS [C7], [Project36].[C8] AS [C8], [Project36].[C9] AS [C9], [Project36].[C10] AS [C10], [Project36].[C11] AS [C11], [Project36].[C12] AS [C12] FROM ( SELECT [Project34].[ReportSemiID] AS [ReportSemiID], [Project34].[SendDate] AS [SendDate], [Project34].[Remark] AS [Remark], [Project34].[GoodsName] AS [GoodsName], [Project34].[SamplingPlaceName] AS [SamplingPlaceName], [Project34].[ProductionLineName] AS [ProductionLineName], [Project34].[ProductionGroupName] AS [ProductionGroupName], [Project34].[EmpName] AS [EmpName], [Project34].[C1] AS [C1], [Project34].[C2] AS [C2], [Project34].[C3] AS [C3], [Project34].[C4] AS [C4], [Project34].[C5] AS [C5], [Project34].[C6] AS [C6], [Project34].[C7] AS [C7], [Project34].[C8] AS [C8], [Project34].[C9] AS [C9], [Project34].[C10] AS [C10], [Project34].[C11] AS [C11], (SELECT TOP (1) [Extent18].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent18] WHERE ([Project34].[ReportSemiID] = [Extent18].[ReportSemiID]) AND ('16' = [Extent18].[TestItemID])) AS [C12] FROM ( SELECT [Project33].[ReportSemiID] AS [ReportSemiID], [Project33].[SendDate] AS [SendDate], [Project33].[Remark] AS [Remark], [Project33].[GoodsName] AS [GoodsName], [Project33].[SamplingPlaceName] AS [SamplingPlaceName], [Project33].[ProductionLineName] AS [ProductionLineName], [Project33].[ProductionGroupName] AS [ProductionGroupName], [Project33].[EmpName] AS [EmpName], [Project33].[C1] AS [C1], [Project33].[C2] AS [C2], [Project33].[C3] AS [C3], [Project33].[C4] AS [C4], [Project33].[C5] AS [C5], [Project33].[C6] AS [C6], [Project33].[C7] AS [C7], [Project33].[C8] AS [C8], [Project33].[C9] AS [C9], [Project33].[C10] AS [C10], [Project33].[C11] AS [C11] FROM ( SELECT [Project31].[ReportSemiID] AS [ReportSemiID], [Project31].[SendDate] AS [SendDate], [Project31].[Remark] AS [Remark], [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[ProductionLineName] AS [ProductionLineName], [Project31].[ProductionGroupName] AS [ProductionGroupName], [Project31].[EmpName] AS [EmpName], [Project31].[C1] AS [C1], [Project31].[C2] AS [C2], [Project31].[C3] AS [C3], [Project31].[C4] AS [C4], [Project31].[C5] AS [C5], [Project31].[C6] AS [C6], [Project31].[C7] AS [C7], [Project31].[C8] AS [C8], [Project31].[C9] AS [C9], [Project31].[C10] AS [C10], (SELECT TOP (1) [Extent17].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent17] WHERE ([Project31].[ReportSemiID] = [Extent17].[ReportSemiID]) AND ('15' = [Extent17].[TestItemID])) AS [C11] FROM ( SELECT [Project30].[ReportSemiID] AS [ReportSemiID], [Project30].[SendDate] AS [SendDate], [Project30].[Remark] AS [Remark], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[ProductionLineName] AS [ProductionLineName], [Project30].[ProductionGroupName] AS [ProductionGroupName], [Project30].[EmpName] AS [EmpName], [Project30].[C1] AS [C1], [Project30].[C2] AS [C2], [Project30].[C3] AS [C3], [Project30].[C4] AS [C4], [Project30].[C5] AS [C5], [Project30].[C6] AS [C6], [Project30].[C7] AS [C7], [Project30].[C8] AS [C8], [Project30].[C9] AS [C9], [Project30].[C10] AS [C10] FROM ( SELECT [Project28].[ReportSemiID] AS [ReportSemiID], [Project28].[SendDate] AS [SendDate], [Project28].[Remark] AS [Remark], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[ProductionLineName] AS [ProductionLineName], [Project28].[ProductionGroupName] AS [ProductionGroupName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent16] WHERE ([Project28].[ReportSemiID] = [Extent16].[ReportSemiID]) AND ('14' = [Extent16].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportSemiID] AS [ReportSemiID], [Project27].[SendDate] AS [SendDate], [Project27].[Remark] AS [Remark], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[ProductionLineName] AS [ProductionLineName], [Project27].[ProductionGroupName] AS [ProductionGroupName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportSemiID] AS [ReportSemiID], [Project25].[SendDate] AS [SendDate], [Project25].[Remark] AS [Remark], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[ProductionLineName] AS [ProductionLineName], [Project25].[ProductionGroupName] AS [ProductionGroupName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent15] WHERE ([Project25].[ReportSemiID] = [Extent15].[ReportSemiID]) AND ('13' = [Extent15].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportSemiID] AS [ReportSemiID], [Project24].[SendDate] AS [SendDate], [Project24].[Remark] AS [Remark], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[ProductionLineName] AS [ProductionLineName], [Project24].[ProductionGroupName] AS [ProductionGroupName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportSemiID] AS [ReportSemiID], [Project22].[SendDate] AS [SendDate], [Project22].[Remark] AS [Remark], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[ProductionLineName] AS [ProductionLineName], [Project22].[ProductionGroupName] AS [ProductionGroupName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent14] WHERE ([Project22].[ReportSemiID] = [Extent14].[ReportSemiID]) AND ('12' = [Extent14].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportSemiID] AS [ReportSemiID], [Project21].[SendDate] AS [SendDate], [Project21].[Remark] AS [Remark], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[ProductionLineName] AS [ProductionLineName], [Project21].[ProductionGroupName] AS [ProductionGroupName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportSemiID] AS [ReportSemiID], [Project19].[SendDate] AS [SendDate], [Project19].[Remark] AS [Remark], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[ProductionLineName] AS [ProductionLineName], [Project19].[ProductionGroupName] AS [ProductionGroupName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent13] WHERE ([Project19].[ReportSemiID] = [Extent13].[ReportSemiID]) AND ('10' = [Extent13].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportSemiID] AS [ReportSemiID], [Project18].[SendDate] AS [SendDate], [Project18].[Remark] AS [Remark], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[ProductionLineName] AS [ProductionLineName], [Project18].[ProductionGroupName] AS [ProductionGroupName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportSemiID] AS [ReportSemiID], [Project16].[SendDate] AS [SendDate], [Project16].[Remark] AS [Remark], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[ProductionLineName] AS [ProductionLineName], [Project16].[ProductionGroupName] AS [ProductionGroupName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent12] WHERE ([Project16].[ReportSemiID] = [Extent12].[ReportSemiID]) AND ('9' = [Extent12].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportSemiID] AS [ReportSemiID], [Project15].[SendDate] AS [SendDate], [Project15].[Remark] AS [Remark], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[ProductionLineName] AS [ProductionLineName], [Project15].[ProductionGroupName] AS [ProductionGroupName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportSemiID] AS [ReportSemiID], [Project13].[SendDate] AS [SendDate], [Project13].[Remark] AS [Remark], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[ProductionLineName] AS [ProductionLineName], [Project13].[ProductionGroupName] AS [ProductionGroupName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent11] WHERE ([Project13].[ReportSemiID] = [Extent11].[ReportSemiID]) AND ('30' = [Extent11].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportSemiID] AS [ReportSemiID], [Project12].[SendDate] AS [SendDate], [Project12].[Remark] AS [Remark], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[ProductionLineName] AS [ProductionLineName], [Project12].[ProductionGroupName] AS [ProductionGroupName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportSemiID] AS [ReportSemiID], [Project10].[SendDate] AS [SendDate], [Project10].[Remark] AS [Remark], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[ProductionLineName] AS [ProductionLineName], [Project10].[ProductionGroupName] AS [ProductionGroupName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent10] WHERE ([Project10].[ReportSemiID] = [Extent10].[ReportSemiID]) AND ('8' = [Extent10].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportSemiID] AS [ReportSemiID], [Project9].[SendDate] AS [SendDate], [Project9].[Remark] AS [Remark], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[ProductionLineName] AS [ProductionLineName], [Project9].[ProductionGroupName] AS [ProductionGroupName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportSemiID] AS [ReportSemiID], [Project7].[SendDate] AS [SendDate], [Project7].[Remark] AS [Remark], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[ProductionLineName] AS [ProductionLineName], [Project7].[ProductionGroupName] AS [ProductionGroupName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent9] WHERE ([Project7].[ReportSemiID] = [Extent9].[ReportSemiID]) AND ('46' = [Extent9].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportSemiID] AS [ReportSemiID], [Project6].[SendDate] AS [SendDate], [Project6].[Remark] AS [Remark], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[ProductionLineName] AS [ProductionLineName], [Project6].[ProductionGroupName] AS [ProductionGroupName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportSemiID] AS [ReportSemiID], [Project4].[SendDate] AS [SendDate], [Project4].[Remark] AS [Remark], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[ProductionLineName] AS [ProductionLineName], [Project4].[ProductionGroupName] AS [ProductionGroupName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent8] WHERE ([Project4].[ReportSemiID] = [Extent8].[ReportSemiID]) AND ('7' = [Extent8].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportSemiID] AS [ReportSemiID], [Project3].[SendDate] AS [SendDate], [Project3].[Remark] AS [Remark], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[ProductionLineName] AS [ProductionLineName], [Project3].[ProductionGroupName] AS [ProductionGroupName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportSemiID] AS [ReportSemiID], [Project1].[SendDate] AS [SendDate], [Project1].[Remark] AS [Remark], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[ProductionLineName] AS [ProductionLineName], [Project1].[ProductionGroupName] AS [ProductionGroupName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportSemiResults] AS [Extent7] WHERE ([Project1].[ReportSemiID] = [Extent7].[ReportSemiID]) AND ('1' = [Extent7].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportSemiID] AS [ReportSemiID], [Filter1].[SendDate] AS [SendDate], [Filter1].[Remark1] AS [Remark], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Filter1].[ProductionLineName] AS [ProductionLineName], [Filter1].[ProductionGroupName] AS [ProductionGroupName], [Extent6].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportSemiID] AS [ReportSemiID], [Extent1].[SendDate] AS [SendDate], [Extent1].[Remark] AS [Remark1], [Extent1].[LoginUserID] AS [LoginUserID], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[ProductionLineName] AS [ProductionLineName], [Extent5].[ProductionGroupName] AS [ProductionGroupName] FROM [dbo].[ReportSemis] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaces] AS [Extent3] ON [Extent1].[SamplingPlaceID] = [Extent3].[SamplingPlaceID] INNER JOIN [dbo].[ProductionLines] AS [Extent4] ON [Extent1].[ProductionLineID] = [Extent4].[ProductionLineID] INNER JOIN [dbo].[ProductionGroups] AS [Extent5] ON [Extent1].[ProductionGroupID] = [Extent5].[ProductionGroupID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('2' = [Extent1].[SamplingPlaceID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent6] ON [Filter1].[LoginUserID] = [Extent6].[LoginUserID] WHERE ([Filter1].[SendDate] <= @EndDate) AND ([Filter1].[SendDate] >= @StartDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ) AS [Project33] ) AS [Project34] ) AS [Project36] ) AS [Project37] ) AS [Project39] ) AS [Project40] ) AS [Project42] ) AS [Project43] ) AS [Project45] ) AS [Project46] ) AS [Project48] ) AS [Project49] ) AS [Project51] ) AS [Project52] ORDER BY [Project52].[SendDate] ASC";
            
            foreach (var goods in goodsSemiList)
            {
                //this month
                SqlParameter startDateSqlParameterMonth = new SqlParameter("@StartDate", startDate);
                SqlParameter endDateSqlParameterMonth = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterMonth = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersMonth = new SqlParameter[] { startDateSqlParameterMonth, endDateSqlParameterMonth, GoodsIDSqlParameterMonth };
                //this year
                SqlParameter startDateSqlParameterYear = new SqlParameter("@StartDate", new DateTime(startDate.Year, 01, 01));
                SqlParameter endDateSqlParameterYear = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterYear = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersYear = new SqlParameter[] { startDateSqlParameterYear, endDateSqlParameterYear, GoodsIDSqlParameterYear };


                DoMonthReportModel reportModel = new DoMonthReportModel();
                reportModel.dataTableThisMonth = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersMonth);
                reportModel.dataTableThisYear = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersYear);

                reportModel.viewStartRowIndex = startRowIndex;
                reportModel.viewEndRowIndex = startRowIndex + 14;     //16 表格    28曲线图  2空行

                reportModel.monthDataStartRowIndex = startRowIndexMonth;
                reportModel.monthDataEndRowIndex = startRowIndexMonth + reportModel.dataTableThisMonth.Rows.Count + 8;

                reportModel.yearDataStartRowIndex = startRowIndexYear;
                reportModel.yearDataEndRowIndex = startRowIndexYear + reportModel.dataTableThisYear.Rows.Count + 8;

                reportModel.goodsName = goods.GoodsName;
                reportModel.standardSemiList = db.StandardSemis.Where(m => m.GoodsID == goods.GoodsID && m.SamplingPlaceID == CommonData.SamplingPlace_Do_ID).ToList();

                if (reportModel.dataTableThisMonth.Rows.Count > 0)
                {
                    DoData.Add(reportModel);
                    startRowIndex = reportModel.viewEndRowIndex + 2;
                    startRowIndexMonth = reportModel.monthDataEndRowIndex + 2;
                    startRowIndexYear = reportModel.yearDataEndRowIndex + 2;
                }
            }

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetCompThisMonth = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetCompThisYear = workbook.Worksheets["Comp_ThisYearData"];
            Worksheet worksheetCompView = workbook.Worksheets["2)Comp"];

            worksheetCompView.Columns[2].Width = 600;

            for (int i = 0; i < DoData.Count; i++)
            {
                worksheetCompThisMonth.Import(DoData[i].dataTableThisMonth, true, DoData[i].monthDataStartRowIndex, 1);
                worksheetCompThisYear.Import(DoData[i].dataTableThisYear, true, DoData[i].yearDataStartRowIndex, 1);

                worksheetCompView[DoData[i].viewStartRowIndex + 5, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();
                worksheetCompView[DoData[i].viewStartRowIndex + 11, 2].Value = new DateTime(startDate.Year, 01, 01).ToShortDateString() + "--" + endDate.ToShortDateString();

                //写Month标准
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 6, 1].Value = "USL";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 6, 1].Value = "USL";

                WriteCompDataStanard(DoData[i], 8, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 9, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 14, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 15, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 16, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 17, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 18, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_LT_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 19, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_PD_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 20, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_PH_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 21, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Tint_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 22, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_CDBP_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 23, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_N2SA_ID).FirstOrDefault());
                WriteCompDataStanard(DoData[i], 24, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Ash_ID).FirstOrDefault());



                WriteCompViewStandard(DoData[i], 4, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 5, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 6, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 7, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 8, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 9, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WriteCompViewStandard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());

                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 5, 1].Value = "Count";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 0, 1].Value = "Cpk";

                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 5, 1].Value = "Count";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 0, 1].Value = "Cpk";



                for (int c = 8; c < 25; c++)
                {
                    Cell cellLT = worksheetCompThisMonth[DoData[i].monthDataStartRowIndex + 1, c];
                    Cell cellRB = worksheetCompThisMonth[DoData[i].monthDataStartRowIndex + 1 + DoData[i].dataTableThisMonth.Rows.Count - 1, c];
                    //count Month   COUNTA
                    string formulaCount = "COUNTA(" + cellLT.GetReferenceA1() + ":" + "'" + cellRB.Worksheet.Name + "'" + "!" + cellRB.GetReferenceA1() + ")";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 5, c].ArrayFormula = formulaCount;
                    //avg Month
                    string formulaAvg = @"=IFERROR(AVERAGEIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">=0\"," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "),\"\")";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, c].ArrayFormula = formulaAvg;
                    Cell avg = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //max Month  =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMax = "=MAX(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 1, c].ArrayFormula = formulaMax;
                    Cell MAX = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //Min Month   =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMin = "=MIN(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 2, c].ArrayFormula = formulaMin;
                    //std Month      =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEV = "=IFERROR(STDEV(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")),\"\")";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEV;
                    //cpk   Month   "'" + cellLT.Worksheet.Name + "'" + "!" +
                    string cellLSL = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSL = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVG = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStd = worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPK = "=IFERROR(IF(AND(" + cellUSL + "=\"\"," + cellLSL + "=\"\"),\"\",MIN((" + cellUSL + "-" + cellAVG + ")/3/" + cellStd + ",(" + cellAVG + "-" + cellLSL + ")/3/" + cellStd + ")),\"\")";
                    worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 0, c].ArrayFormula = formulaCPK;

                    string countMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetCompThisMonth[DoData[i].monthDataEndRowIndex - 0, c].GetReferenceA1();



                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 4, c - 4, countMonthFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 5, c - 4, avgMonthFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 6, c - 4, STDEVMonthFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 7, c - 4, MinMonthFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 8, c - 4, MaxMonthFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 9, c - 4, CPKMonthFormula);



                    /////////////////////////////////////////////统计this Year
                    Cell cellLTYaer = worksheetCompThisYear[DoData[i].yearDataStartRowIndex + 1, c];
                    Cell cellRBYaer = worksheetCompThisYear[DoData[i].yearDataStartRowIndex + 1 + DoData[i].dataTableThisYear.Rows.Count - 1, c];
                    //count  COUNTA
                    string formulaCountYear = "COUNTA(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 5, c].Formula = formulaCountYear;
                    //avg Month
                    string formulaAvgYear = @"=IFERROR(AVERAGEIF(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ",\">=0\"," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "),\"\")";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, c].ArrayFormula = formulaAvgYear;
                    Cell avgYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //max Month   =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMaxYear = "=MAX(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 1, c].ArrayFormula = formulaMaxYear;
                    Cell MAXYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //Min Month      =MIN(IF((E7:E66>0),E7:E66))  
                    string formulaMinYear = "=MIN(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 2, c].ArrayFormula = formulaMinYear;
                    //std Month   =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEVYear = "=IFERROR(STDEV(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")),\"\")";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEVYear;
                    //cpk   Month   "'" + cellLTYaer.Worksheet.Name + "'" + "!" + 
                    string cellLSLYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSLYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVGYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStdYear = worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPKYear = "=IFERROR(IF(AND(" + cellUSLYear + "=\"\"," + cellLSLYear + "=\"\"),\"\",MIN((" + cellUSLYear + "-" + cellAVGYear + ")/3/" + cellStdYear + ",(" + cellAVGYear + "-" + cellLSLYear + ")/3/" + cellStdYear + ")),\"\")";
                    worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 0, c].ArrayFormula = formulaSTDEVYear;

                    string countYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetCompThisYear[DoData[i].yearDataEndRowIndex - 0, c].GetReferenceA1();


                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 10, c - 4, countYearFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 11, c - 4, avgYearFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 12, c - 4, STDEVYearFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 13, c - 4, MinYearFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 14, c - 4, MaxYearFormula);
                    CompWriteDataDetail(DoData[i].viewStartRowIndex + 15, c - 4, CPKYearFormula);

                }
                WriteCompStanardColumn(DoData[i], 26, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Tint_ID).FirstOrDefault(), "Tint");
                CompWriteTitel(DoData[i], i);
                CompDecorate(DoData[i], startDate, endDate);

                ///开始添加 曲线图
                // 19 IA
                CompCreateChart(DoData[i], worksheetCompView[DoData[i].viewStartRowIndex, 21], worksheetCompView[DoData[i].viewStartRowIndex + 15, 29]);




            }

        }
        private void WriteCompDataStanard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetDO_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetDO_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];


            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetDO_ThisMonthData[reportModel.monthDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                    worksheetDO_ThisYearData[reportModel.yearDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetDO_ThisMonthData[reportModel.monthDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                    worksheetDO_ThisYearData[reportModel.yearDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void WriteCompViewStandard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)Comp"];
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void WriteCompDataColumnStanard(DoMonthReportModel reportModel, int column, StandardSemi standard, string columnName)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetDO_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetDO_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];

            worksheetDO_ThisMonthData[reportModel.monthDataStartRowIndex, column].Value = columnName + "_LSL";
            worksheetDO_ThisMonthData[reportModel.monthDataStartRowIndex, column + 1].Value = columnName + "_USL";
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    Range rangeIA_LSL = worksheetDO_ThisMonthData.Range.FromLTRB(column, reportModel.monthDataStartRowIndex + 1, column, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    Range rangeIA_LSL = worksheetDO_ThisMonthData.Range.FromLTRB(column + 1, reportModel.monthDataStartRowIndex + 1, column + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        private void CompWriteDataDetail(int row, int column, string formula)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["2)Comp"];
            worksheetDoView[row, column].Formula = formula;
        }

        private void CompWriteTitel(DoMonthReportModel semiReport, int NO)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDO = workbook.Worksheets["2)Comp"];

            // 第一行  Unit    Grade   
            worksheetDO[semiReport.viewStartRowIndex, 0].Value = "Unit";
            worksheetDO[semiReport.viewStartRowIndex, 1].Value = "Grade";
            worksheetDO[semiReport.viewStartRowIndex, 2].Value = "Month";
            worksheetDO[semiReport.viewStartRowIndex, 3].Value = "Category";
            worksheetDO[semiReport.viewStartRowIndex, 4].Value = "IA(g/kg)";
            worksheetDO[semiReport.viewStartRowIndex, 5].Value = "DBP(ml/100g)";
            worksheetDO[semiReport.viewStartRowIndex, 6].Value = "IPH(gf)";
            worksheetDO[semiReport.viewStartRowIndex, 9].Value = "Fines(%)";
            worksheetDO[semiReport.viewStartRowIndex, 10].Value = "HL(%)";
            worksheetDO[semiReport.viewStartRowIndex, 11].Value = "Sieve Residue(ppm)";

            worksheetDO[semiReport.viewStartRowIndex, 14].Value = "LT(%)";
            worksheetDO[semiReport.viewStartRowIndex, 15].Value = "PD(kg/m³)";
            worksheetDO[semiReport.viewStartRowIndex, 16].Value = "PH";
            worksheetDO[semiReport.viewStartRowIndex, 17].Value = "Tint(%)";
            worksheetDO[semiReport.viewStartRowIndex, 18].Value = "CDBP(ml/100g)";
            worksheetDO[semiReport.viewStartRowIndex, 19].Value = "N2SA(㎡/g)";
            worksheetDO[semiReport.viewStartRowIndex, 20].Value = "Ash(%)";
            //第二行
            worksheetDO[semiReport.viewStartRowIndex + 1, 6].Value = "AVG";
            worksheetDO[semiReport.viewStartRowIndex + 1, 7].Value = "High";
            worksheetDO[semiReport.viewStartRowIndex + 1, 8].Value = "Low";
            worksheetDO[semiReport.viewStartRowIndex + 1, 11].Value = "#35";
            worksheetDO[semiReport.viewStartRowIndex + 1, 12].Value = "#100";
            worksheetDO[semiReport.viewStartRowIndex + 1, 13].Value = "#325";
            //合并单元格  横向 IPH     Sieve
            Range rangeIPH = worksheetDO.Range.FromLTRB(6, semiReport.viewStartRowIndex, 8, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeIPH);
            Range rangeSieve = worksheetDO.Range.FromLTRB(11, semiReport.viewStartRowIndex, 13, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeSieve);
            //合并单元格 zongxiang
            int[] intArray = new int[] { 0, 1, 2, 3, 4, 5, 9, 10 };
            foreach (int i in intArray)
            {
                Range rangeUnit = worksheetDO.Range.FromLTRB(i, semiReport.viewStartRowIndex, i, semiReport.viewStartRowIndex + 1);
                worksheetDO.MergeCells(rangeUnit);
            }
            //标题第一行加高
            RowCollection rows = worksheetDO.Rows;
            Row row_byIndex = rows[semiReport.viewStartRowIndex];
            row_byIndex.RowHeight = 140;
            //字体加粗  居中

            //合并Unit 下方单元格   Grade下方单元格
            Range rangeUnitDetail = worksheetDO.Range.FromLTRB(0, semiReport.viewStartRowIndex + 2, 0, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Value = NO + 1;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            Range rangeGradeDetail = worksheetDO.Range.FromLTRB(1, semiReport.viewStartRowIndex + 2, 1, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Value = semiReport.goodsName;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            worksheetDO.MergeCells(rangeUnitDetail);
            worksheetDO.MergeCells(rangeGradeDetail);
            //合并month下方 spec‘单元格
            Range rangeSpec = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 2, 2, semiReport.viewStartRowIndex + 3);
            worksheetDO.MergeCells(rangeSpec);
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Value = "spec'";
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 Month‘单元格
            Range rangeMonthCurrent = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 4, 2, semiReport.viewStartRowIndex + 9);
            worksheetDO.MergeCells(rangeMonthCurrent);
            // worksheetDO[semiReport.viewStartRowIndex + 4, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();       //当前月份
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 之前月份 ‘单元格
            Range rangeMonthBefore = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 10, 2, semiReport.viewStartRowIndex + 15);
            worksheetDO.MergeCells(rangeMonthBefore);

            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //Category
            worksheetDO[semiReport.viewStartRowIndex + 2, 3].Value = "LSL";
            worksheetDO[semiReport.viewStartRowIndex + 3, 3].Value = "USL";
            worksheetDO[semiReport.viewStartRowIndex + 4, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 5, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 6, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 7, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 8, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 9, 3].Value = "Cpk";

            worksheetDO[semiReport.viewStartRowIndex + 10, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 11, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 12, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 13, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 14, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 15, 3].Value = "Cpk";
        }

        private void CompDecorate(DoMonthReportModel reportModel, DateTime startDate, DateTime endDate)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["2)Comp"];
            //加边框
            Range range = worksheetDoView.Range.FromLTRB(0, reportModel.viewStartRowIndex, 20, reportModel.viewStartRowIndex + 15);
            range.SetInsideBorders(Color.Black, BorderLineStyle.Dashed);
            range.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
            range.Font.Bold = true;
            Formatting rangeFormatting1 = range.BeginUpdateFormatting();
            rangeFormatting1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            range.EndUpdateFormatting(rangeFormatting1);
            //一年的数据加背景颜色
            Range rangeYear = worksheetDoView.Range.FromLTRB(2, reportModel.viewStartRowIndex + 10, 20, reportModel.viewStartRowIndex + 15);

            Formatting rangeFormatting2 = rangeYear.BeginUpdateFormatting();
            rangeFormatting2.Fill.BackgroundColor = Color.FromArgb(204, 255, 204);
            rangeFormatting2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            rangeYear.EndUpdateFormatting(rangeFormatting2);


        }

        private void CompCreateChart(DoMonthReportModel reportModel, Cell TopLeftCell, Cell BottomRightCell)
        {
            //  IA  DBP 
            //FInes SR#325
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetCompView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetComp_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetComp_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];

            Chart chartIA = worksheetCompView.Charts.Add(ChartType.ScatterLineMarkers);
            chartIA.TopLeftCell = TopLeftCell;
            chartIA.BottomRightCell = BottomRightCell;
            //创建IA的 曲线
            Range nameIARane = worksheetComp_ThisMonthData.Range.FromLTRB(21, reportModel.monthDataStartRowIndex, 21, reportModel.monthDataStartRowIndex);
            Range valueRange = worksheetComp_ThisMonthData.Range.FromLTRB(21, reportModel.monthDataStartRowIndex + 1, 21, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            Range agumentRage = worksheetComp_ThisMonthData.Range.FromLTRB(5, reportModel.monthDataStartRowIndex + 1, 5, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameIARane, agumentRage, valueRange);

            //下限
            Range nameLSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26, reportModel.monthDataStartRowIndex, 26, reportModel.monthDataStartRowIndex);
            Range valueLSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26, reportModel.monthDataStartRowIndex + 1, 26, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameLSLRange, agumentRage, valueLSLRange);
            //上线
            Range nameUSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26 + 1, reportModel.monthDataStartRowIndex, 26 + 1, reportModel.monthDataStartRowIndex);
            Range valueUSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26 + 1, reportModel.monthDataStartRowIndex + 1, 26 + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameUSLRange, agumentRage, valueUSLRange);



            chartIA.Legend.Position = LegendPosition.Bottom;
            chartIA.Title.Visible = true;
            chartIA.Title.SetValue(reportModel.goodsName);








        }

        private void WriteCompStanardColumn(DoMonthReportModel reportModel, int column, StandardSemi standard, string columnName)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetCompView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetComp_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetComp_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];

            worksheetComp_ThisMonthData[reportModel.monthDataStartRowIndex, column].Value = columnName + "_LSL";
            worksheetComp_ThisMonthData[reportModel.monthDataStartRowIndex, column + 1].Value = columnName + "_USL";
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    Range rangeIA_LSL = worksheetComp_ThisMonthData.Range.FromLTRB(column, reportModel.monthDataStartRowIndex + 1, column, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    Range rangeIA_LSL = worksheetComp_ThisMonthData.Range.FromLTRB(column + 1, reportModel.monthDataStartRowIndex + 1, column + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        #endregion

        #region 包装复检取样

        private void InitPackingReport(DateTime startDate, DateTime endDate)
        {
            int startRowIndex = 1;
            int startRowIndexMonth = 0;
            int startRowIndexYear = 0;

            List<Good> goodsSemiList = db.Goods.Where(m => m.GoodsTypeID == CommonData.GoodsType_Production_ID).ToList();
            List<DoMonthReportModel> DataList = new List<DoMonthReportModel>();
            //string sql = "SELECT [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[TestDate] AS [TestDate], [Project31].[ProduceDate] AS [ProduceDate], [Project31].[ReportNO] AS [ReportNO], [Project31].[LotNO] AS [LotNO], [Project31].[EmpName] AS [EmpName], CONVERT(float, [Project31].[C2]) AS [IA], CONVERT(float,[Project31].[C3] )AS [DBP], CONVERT(float,[Project31].[C4]) AS [IPH(AVG)], CONVERT(float,[Project31].[C5]) AS [IPH(High)], CONVERT(float,[Project31].[C6] )AS [IPH(Low)], CONVERT(float,[Project31].[C7]) AS [Fines], CONVERT(float,[Project31].[C8] )AS [HL], CONVERT(float,[Project31].[C9]) AS [SieveResidue#35], CONVERT(float, [Project31].[C10]) AS [SieveResidue#100], CONVERT(float,[Project31].[C11] )AS [SieveResidue#325] FROM ( SELECT [Project30].[ProduceDate] AS [ProduceDate], [Project30].[SendDate] AS [SendDate], [Project30].[LotNO] AS [LotNO], [Project30].[TestDate] AS [TestDate], [Project30].[ReportNO] AS [ReportNO], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[EmpName] AS [EmpName], 1 AS [C1], [Project30].[C1] AS [C2], [Project30].[C2] AS [C3], [Project30].[C3] AS [C4], [Project30].[C4] AS [C5], [Project30].[C5] AS [C6], [Project30].[C6] AS [C7], [Project30].[C7] AS [C8], [Project30].[C8] AS [C9], [Project30].[C9] AS [C10], [Project30].[C10] AS [C11] FROM ( SELECT [Project28].[ReportMixID] AS [ReportMixID], [Project28].[ProduceDate] AS [ProduceDate], [Project28].[SendDate] AS [SendDate], [Project28].[LotNO] AS [LotNO], [Project28].[TestDate] AS [TestDate], [Project28].[ReportNO] AS [ReportNO], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent14] WHERE ([Project28].[ReportMixID] = [Extent14].[ReportMixID]) AND ('14' = [Extent14].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportMixID] AS [ReportMixID], [Project27].[ProduceDate] AS [ProduceDate], [Project27].[SendDate] AS [SendDate], [Project27].[LotNO] AS [LotNO], [Project27].[TestDate] AS [TestDate], [Project27].[ReportNO] AS [ReportNO], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportMixID] AS [ReportMixID], [Project25].[ProduceDate] AS [ProduceDate], [Project25].[SendDate] AS [SendDate], [Project25].[LotNO] AS [LotNO], [Project25].[TestDate] AS [TestDate], [Project25].[ReportNO] AS [ReportNO], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent13] WHERE ([Project25].[ReportMixID] = [Extent13].[ReportMixID]) AND ('13' = [Extent13].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportMixID] AS [ReportMixID], [Project24].[ProduceDate] AS [ProduceDate], [Project24].[SendDate] AS [SendDate], [Project24].[LotNO] AS [LotNO], [Project24].[TestDate] AS [TestDate], [Project24].[ReportNO] AS [ReportNO], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportMixID] AS [ReportMixID], [Project22].[ProduceDate] AS [ProduceDate], [Project22].[SendDate] AS [SendDate], [Project22].[LotNO] AS [LotNO], [Project22].[TestDate] AS [TestDate], [Project22].[ReportNO] AS [ReportNO], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent12] WHERE ([Project22].[ReportMixID] = [Extent12].[ReportMixID]) AND ('12' = [Extent12].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportMixID] AS [ReportMixID], [Project21].[ProduceDate] AS [ProduceDate], [Project21].[SendDate] AS [SendDate], [Project21].[LotNO] AS [LotNO], [Project21].[TestDate] AS [TestDate], [Project21].[ReportNO] AS [ReportNO], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportMixID] AS [ReportMixID], [Project19].[ProduceDate] AS [ProduceDate], [Project19].[SendDate] AS [SendDate], [Project19].[LotNO] AS [LotNO], [Project19].[TestDate] AS [TestDate], [Project19].[ReportNO] AS [ReportNO], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent11] WHERE ([Project19].[ReportMixID] = [Extent11].[ReportMixID]) AND ('10' = [Extent11].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportMixID] AS [ReportMixID], [Project18].[ProduceDate] AS [ProduceDate], [Project18].[SendDate] AS [SendDate], [Project18].[LotNO] AS [LotNO], [Project18].[TestDate] AS [TestDate], [Project18].[ReportNO] AS [ReportNO], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportMixID] AS [ReportMixID], [Project16].[ProduceDate] AS [ProduceDate], [Project16].[SendDate] AS [SendDate], [Project16].[LotNO] AS [LotNO], [Project16].[TestDate] AS [TestDate], [Project16].[ReportNO] AS [ReportNO], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent10] WHERE ([Project16].[ReportMixID] = [Extent10].[ReportMixID]) AND ('9' = [Extent10].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportMixID] AS [ReportMixID], [Project15].[ProduceDate] AS [ProduceDate], [Project15].[SendDate] AS [SendDate], [Project15].[LotNO] AS [LotNO], [Project15].[TestDate] AS [TestDate], [Project15].[ReportNO] AS [ReportNO], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportMixID] AS [ReportMixID], [Project13].[ProduceDate] AS [ProduceDate], [Project13].[SendDate] AS [SendDate], [Project13].[LotNO] AS [LotNO], [Project13].[TestDate] AS [TestDate], [Project13].[ReportNO] AS [ReportNO], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent9] WHERE ([Project13].[ReportMixID] = [Extent9].[ReportMixID]) AND ('30' = [Extent9].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportMixID] AS [ReportMixID], [Project12].[ProduceDate] AS [ProduceDate], [Project12].[SendDate] AS [SendDate], [Project12].[LotNO] AS [LotNO], [Project12].[TestDate] AS [TestDate], [Project12].[ReportNO] AS [ReportNO], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportMixID] AS [ReportMixID], [Project10].[ProduceDate] AS [ProduceDate], [Project10].[SendDate] AS [SendDate], [Project10].[LotNO] AS [LotNO], [Project10].[TestDate] AS [TestDate], [Project10].[ReportNO] AS [ReportNO], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent8] WHERE ([Project10].[ReportMixID] = [Extent8].[ReportMixID]) AND ('8' = [Extent8].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportMixID] AS [ReportMixID], [Project9].[ProduceDate] AS [ProduceDate], [Project9].[SendDate] AS [SendDate], [Project9].[LotNO] AS [LotNO], [Project9].[TestDate] AS [TestDate], [Project9].[ReportNO] AS [ReportNO], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportMixID] AS [ReportMixID], [Project7].[ProduceDate] AS [ProduceDate], [Project7].[SendDate] AS [SendDate], [Project7].[LotNO] AS [LotNO], [Project7].[TestDate] AS [TestDate], [Project7].[ReportNO] AS [ReportNO], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent7] WHERE ([Project7].[ReportMixID] = [Extent7].[ReportMixID]) AND ('46' = [Extent7].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportMixID] AS [ReportMixID], [Project6].[ProduceDate] AS [ProduceDate], [Project6].[SendDate] AS [SendDate], [Project6].[LotNO] AS [LotNO], [Project6].[TestDate] AS [TestDate], [Project6].[ReportNO] AS [ReportNO], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportMixID] AS [ReportMixID], [Project4].[ProduceDate] AS [ProduceDate], [Project4].[SendDate] AS [SendDate], [Project4].[LotNO] AS [LotNO], [Project4].[TestDate] AS [TestDate], [Project4].[ReportNO] AS [ReportNO], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent6].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent6] WHERE ([Project4].[ReportMixID] = [Extent6].[ReportMixID]) AND ('7' = [Extent6].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportMixID] AS [ReportMixID], [Project3].[ProduceDate] AS [ProduceDate], [Project3].[SendDate] AS [SendDate], [Project3].[LotNO] AS [LotNO], [Project3].[TestDate] AS [TestDate], [Project3].[ReportNO] AS [ReportNO], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportMixID] AS [ReportMixID], [Project1].[ProduceDate] AS [ProduceDate], [Project1].[SendDate] AS [SendDate], [Project1].[LotNO] AS [LotNO], [Project1].[TestDate] AS [TestDate], [Project1].[ReportNO] AS [ReportNO], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent5] WHERE ([Project1].[ReportMixID] = [Extent5].[ReportMixID]) AND ('1' = [Extent5].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportMixID] AS [ReportMixID], [Filter1].[ProduceDate] AS [ProduceDate], [Filter1].[SendDate] AS [SendDate], [Filter1].[LotNO] AS [LotNO], [Filter1].[TestDate] AS [TestDate], [Filter1].[ReportNO] AS [ReportNO], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportMixID] AS [ReportMixID], [Extent1].[ProduceDate] AS [ProduceDate], [Extent1].[SendDate] AS [SendDate], [Extent1].[LotNO] AS [LotNO], [Extent1].[LoginUserID] AS [LoginUserID], [Extent1].[TestDate] AS [TestDate], [Extent1].[ReportNO] AS [ReportNO], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName] FROM [dbo].[ReportMixes] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaceMixes] AS [Extent3] ON [Extent1].[SamplingPlaceMixID] = [Extent3].[SamplingPlaceMixID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('3' = [Extent1].[SamplingPlaceMixID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent4] ON [Filter1].[LoginUserID] = [Extent4].[LoginUserID] WHERE ([Filter1].[TestDate] >= @StartDate) AND ([Filter1].[TestDate] <= @EndDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ORDER BY [Project31].[SendDate] ASC";
            string sql = "SELECT [Project31].[GoodsName] AS [GoodsName], [Project31].[SamplingPlaceName] AS [SamplingPlaceName], [Project31].[TestDate] AS [TestDate], [Project31].[ProduceDate] AS [ProduceDate], [Project31].[ReportNO] AS [ReportNO], [Project31].[LotNO] AS [LotNO], [Project31].[EmpName] AS [EmpName], CASE [Project31].[C2] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C2] ) END AS [IA], CASE [Project31].[C3] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C3] ) END AS [DBP], CASE [Project31].[C4] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C4] ) END AS [IPH(AVG)], CASE [Project31].[C5] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C5] ) END AS [IPH(High)], CASE [Project31].[C6] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C6] ) END AS [IPH(Low)], CASE [Project31].[C7] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C7] ) END AS [Fines], CASE [Project31].[C8] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C8] ) END AS [HL], CASE [Project31].[C9] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C9] ) END AS [Sieve Residue#35], CASE [Project31].[C10] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C10]) END AS [Sieve Residue#100], CASE [Project31].[C11] WHEN '' THEN NUll ELSE CONVERT(float,[Project31].[C11]) END AS [Sieve Residue#325] FROM ( SELECT [Project30].[ProduceDate] AS [ProduceDate], [Project30].[SendDate] AS [SendDate], [Project30].[LotNO] AS [LotNO], [Project30].[TestDate] AS [TestDate], [Project30].[ReportNO] AS [ReportNO], [Project30].[GoodsName] AS [GoodsName], [Project30].[SamplingPlaceName] AS [SamplingPlaceName], [Project30].[EmpName] AS [EmpName], 1 AS [C1], [Project30].[C1] AS [C2], [Project30].[C2] AS [C3], [Project30].[C3] AS [C4], [Project30].[C4] AS [C5], [Project30].[C5] AS [C6], [Project30].[C6] AS [C7], [Project30].[C7] AS [C8], [Project30].[C8] AS [C9], [Project30].[C9] AS [C10], [Project30].[C10] AS [C11] FROM ( SELECT [Project28].[ReportMixID] AS [ReportMixID], [Project28].[ProduceDate] AS [ProduceDate], [Project28].[SendDate] AS [SendDate], [Project28].[LotNO] AS [LotNO], [Project28].[TestDate] AS [TestDate], [Project28].[ReportNO] AS [ReportNO], [Project28].[GoodsName] AS [GoodsName], [Project28].[SamplingPlaceName] AS [SamplingPlaceName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent14] WHERE ([Project28].[ReportMixID] = [Extent14].[ReportMixID]) AND ('14' = [Extent14].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportMixID] AS [ReportMixID], [Project27].[ProduceDate] AS [ProduceDate], [Project27].[SendDate] AS [SendDate], [Project27].[LotNO] AS [LotNO], [Project27].[TestDate] AS [TestDate], [Project27].[ReportNO] AS [ReportNO], [Project27].[GoodsName] AS [GoodsName], [Project27].[SamplingPlaceName] AS [SamplingPlaceName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportMixID] AS [ReportMixID], [Project25].[ProduceDate] AS [ProduceDate], [Project25].[SendDate] AS [SendDate], [Project25].[LotNO] AS [LotNO], [Project25].[TestDate] AS [TestDate], [Project25].[ReportNO] AS [ReportNO], [Project25].[GoodsName] AS [GoodsName], [Project25].[SamplingPlaceName] AS [SamplingPlaceName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent13] WHERE ([Project25].[ReportMixID] = [Extent13].[ReportMixID]) AND ('13' = [Extent13].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportMixID] AS [ReportMixID], [Project24].[ProduceDate] AS [ProduceDate], [Project24].[SendDate] AS [SendDate], [Project24].[LotNO] AS [LotNO], [Project24].[TestDate] AS [TestDate], [Project24].[ReportNO] AS [ReportNO], [Project24].[GoodsName] AS [GoodsName], [Project24].[SamplingPlaceName] AS [SamplingPlaceName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportMixID] AS [ReportMixID], [Project22].[ProduceDate] AS [ProduceDate], [Project22].[SendDate] AS [SendDate], [Project22].[LotNO] AS [LotNO], [Project22].[TestDate] AS [TestDate], [Project22].[ReportNO] AS [ReportNO], [Project22].[GoodsName] AS [GoodsName], [Project22].[SamplingPlaceName] AS [SamplingPlaceName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent12] WHERE ([Project22].[ReportMixID] = [Extent12].[ReportMixID]) AND ('12' = [Extent12].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportMixID] AS [ReportMixID], [Project21].[ProduceDate] AS [ProduceDate], [Project21].[SendDate] AS [SendDate], [Project21].[LotNO] AS [LotNO], [Project21].[TestDate] AS [TestDate], [Project21].[ReportNO] AS [ReportNO], [Project21].[GoodsName] AS [GoodsName], [Project21].[SamplingPlaceName] AS [SamplingPlaceName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportMixID] AS [ReportMixID], [Project19].[ProduceDate] AS [ProduceDate], [Project19].[SendDate] AS [SendDate], [Project19].[LotNO] AS [LotNO], [Project19].[TestDate] AS [TestDate], [Project19].[ReportNO] AS [ReportNO], [Project19].[GoodsName] AS [GoodsName], [Project19].[SamplingPlaceName] AS [SamplingPlaceName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent11] WHERE ([Project19].[ReportMixID] = [Extent11].[ReportMixID]) AND ('10' = [Extent11].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportMixID] AS [ReportMixID], [Project18].[ProduceDate] AS [ProduceDate], [Project18].[SendDate] AS [SendDate], [Project18].[LotNO] AS [LotNO], [Project18].[TestDate] AS [TestDate], [Project18].[ReportNO] AS [ReportNO], [Project18].[GoodsName] AS [GoodsName], [Project18].[SamplingPlaceName] AS [SamplingPlaceName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportMixID] AS [ReportMixID], [Project16].[ProduceDate] AS [ProduceDate], [Project16].[SendDate] AS [SendDate], [Project16].[LotNO] AS [LotNO], [Project16].[TestDate] AS [TestDate], [Project16].[ReportNO] AS [ReportNO], [Project16].[GoodsName] AS [GoodsName], [Project16].[SamplingPlaceName] AS [SamplingPlaceName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent10] WHERE ([Project16].[ReportMixID] = [Extent10].[ReportMixID]) AND ('9' = [Extent10].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportMixID] AS [ReportMixID], [Project15].[ProduceDate] AS [ProduceDate], [Project15].[SendDate] AS [SendDate], [Project15].[LotNO] AS [LotNO], [Project15].[TestDate] AS [TestDate], [Project15].[ReportNO] AS [ReportNO], [Project15].[GoodsName] AS [GoodsName], [Project15].[SamplingPlaceName] AS [SamplingPlaceName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportMixID] AS [ReportMixID], [Project13].[ProduceDate] AS [ProduceDate], [Project13].[SendDate] AS [SendDate], [Project13].[LotNO] AS [LotNO], [Project13].[TestDate] AS [TestDate], [Project13].[ReportNO] AS [ReportNO], [Project13].[GoodsName] AS [GoodsName], [Project13].[SamplingPlaceName] AS [SamplingPlaceName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent9] WHERE ([Project13].[ReportMixID] = [Extent9].[ReportMixID]) AND ('30' = [Extent9].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportMixID] AS [ReportMixID], [Project12].[ProduceDate] AS [ProduceDate], [Project12].[SendDate] AS [SendDate], [Project12].[LotNO] AS [LotNO], [Project12].[TestDate] AS [TestDate], [Project12].[ReportNO] AS [ReportNO], [Project12].[GoodsName] AS [GoodsName], [Project12].[SamplingPlaceName] AS [SamplingPlaceName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportMixID] AS [ReportMixID], [Project10].[ProduceDate] AS [ProduceDate], [Project10].[SendDate] AS [SendDate], [Project10].[LotNO] AS [LotNO], [Project10].[TestDate] AS [TestDate], [Project10].[ReportNO] AS [ReportNO], [Project10].[GoodsName] AS [GoodsName], [Project10].[SamplingPlaceName] AS [SamplingPlaceName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent8] WHERE ([Project10].[ReportMixID] = [Extent8].[ReportMixID]) AND ('8' = [Extent8].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportMixID] AS [ReportMixID], [Project9].[ProduceDate] AS [ProduceDate], [Project9].[SendDate] AS [SendDate], [Project9].[LotNO] AS [LotNO], [Project9].[TestDate] AS [TestDate], [Project9].[ReportNO] AS [ReportNO], [Project9].[GoodsName] AS [GoodsName], [Project9].[SamplingPlaceName] AS [SamplingPlaceName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportMixID] AS [ReportMixID], [Project7].[ProduceDate] AS [ProduceDate], [Project7].[SendDate] AS [SendDate], [Project7].[LotNO] AS [LotNO], [Project7].[TestDate] AS [TestDate], [Project7].[ReportNO] AS [ReportNO], [Project7].[GoodsName] AS [GoodsName], [Project7].[SamplingPlaceName] AS [SamplingPlaceName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent7] WHERE ([Project7].[ReportMixID] = [Extent7].[ReportMixID]) AND ('46' = [Extent7].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportMixID] AS [ReportMixID], [Project6].[ProduceDate] AS [ProduceDate], [Project6].[SendDate] AS [SendDate], [Project6].[LotNO] AS [LotNO], [Project6].[TestDate] AS [TestDate], [Project6].[ReportNO] AS [ReportNO], [Project6].[GoodsName] AS [GoodsName], [Project6].[SamplingPlaceName] AS [SamplingPlaceName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportMixID] AS [ReportMixID], [Project4].[ProduceDate] AS [ProduceDate], [Project4].[SendDate] AS [SendDate], [Project4].[LotNO] AS [LotNO], [Project4].[TestDate] AS [TestDate], [Project4].[ReportNO] AS [ReportNO], [Project4].[GoodsName] AS [GoodsName], [Project4].[SamplingPlaceName] AS [SamplingPlaceName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent6].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent6] WHERE ([Project4].[ReportMixID] = [Extent6].[ReportMixID]) AND ('7' = [Extent6].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportMixID] AS [ReportMixID], [Project3].[ProduceDate] AS [ProduceDate], [Project3].[SendDate] AS [SendDate], [Project3].[LotNO] AS [LotNO], [Project3].[TestDate] AS [TestDate], [Project3].[ReportNO] AS [ReportNO], [Project3].[GoodsName] AS [GoodsName], [Project3].[SamplingPlaceName] AS [SamplingPlaceName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportMixID] AS [ReportMixID], [Project1].[ProduceDate] AS [ProduceDate], [Project1].[SendDate] AS [SendDate], [Project1].[LotNO] AS [LotNO], [Project1].[TestDate] AS [TestDate], [Project1].[ReportNO] AS [ReportNO], [Project1].[GoodsName] AS [GoodsName], [Project1].[SamplingPlaceName] AS [SamplingPlaceName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportMixResults] AS [Extent5] WHERE ([Project1].[ReportMixID] = [Extent5].[ReportMixID]) AND ('1' = [Extent5].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportMixID] AS [ReportMixID], [Filter1].[ProduceDate] AS [ProduceDate], [Filter1].[SendDate] AS [SendDate], [Filter1].[LotNO] AS [LotNO], [Filter1].[TestDate] AS [TestDate], [Filter1].[ReportNO] AS [ReportNO], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[SamplingPlaceName] AS [SamplingPlaceName], [Extent4].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportMixID] AS [ReportMixID], [Extent1].[ProduceDate] AS [ProduceDate], [Extent1].[SendDate] AS [SendDate], [Extent1].[LotNO] AS [LotNO], [Extent1].[LoginUserID] AS [LoginUserID], [Extent1].[TestDate] AS [TestDate], [Extent1].[ReportNO] AS [ReportNO], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[SamplingPlaceName] AS [SamplingPlaceName] FROM [dbo].[ReportMixes] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] INNER JOIN [dbo].[SamplingPlaceMixes] AS [Extent3] ON [Extent1].[SamplingPlaceMixID] = [Extent3].[SamplingPlaceMixID] WHERE (@GoodsID = [Extent1].[GoodsID]) AND ('3' = [Extent1].[SamplingPlaceMixID]) ) AS [Filter1] INNER JOIN [dbo].[LoginUsers] AS [Extent4] ON [Filter1].[LoginUserID] = [Extent4].[LoginUserID] WHERE ([Filter1].[TestDate] >= @StartDate) AND ([Filter1].[TestDate] <= @EndDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ORDER BY [Project31].[SendDate] ASC";

            foreach (var goods in goodsSemiList)
            {
                //this month
                SqlParameter startDateSqlParameterMonth = new SqlParameter("@StartDate", startDate);
                SqlParameter endDateSqlParameterMonth = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterMonth = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersMonth = new SqlParameter[] { startDateSqlParameterMonth, endDateSqlParameterMonth, GoodsIDSqlParameterMonth };
                //this year
                SqlParameter startDateSqlParameterYear = new SqlParameter("@StartDate", new DateTime(startDate.Year, 01, 01));
                SqlParameter endDateSqlParameterYear = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterYear = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersYear = new SqlParameter[] { startDateSqlParameterYear, endDateSqlParameterYear, GoodsIDSqlParameterYear };


                DoMonthReportModel reportModel = new DoMonthReportModel();
                reportModel.dataTableThisMonth = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersMonth);
                reportModel.dataTableThisYear = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersYear);

                reportModel.viewStartRowIndex = startRowIndex;
                reportModel.viewEndRowIndex = startRowIndex + 14;     //16 表格    28曲线图  2空行

                reportModel.monthDataStartRowIndex = startRowIndexMonth;
                reportModel.monthDataEndRowIndex = startRowIndexMonth + reportModel.dataTableThisMonth.Rows.Count + 8;

                reportModel.yearDataStartRowIndex = startRowIndexYear;
                reportModel.yearDataEndRowIndex = startRowIndexYear + reportModel.dataTableThisYear.Rows.Count + 8;

                reportModel.goodsName = goods.GoodsName;
                reportModel.standardSemiList = db.StandardSemis.Where(m => m.GoodsID == goods.GoodsID && m.SamplingPlaceID == CommonData.SamplingPlace_Do_ID).ToList();

                if (reportModel.dataTableThisMonth.Rows.Count > 0)
                {
                    DataList.Add(reportModel);
                    startRowIndex = reportModel.viewEndRowIndex + 2;
                    startRowIndexMonth = reportModel.monthDataEndRowIndex + 2;
                    startRowIndexYear = reportModel.yearDataEndRowIndex + 2;
                }
            }

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetPackingThisMonth = workbook.Worksheets["Packing_ThisMonthData"];
            Worksheet worksheetPackingThisYear = workbook.Worksheets["Packing_ThisYearData"];
            Worksheet worksheetPackingView = workbook.Worksheets["3)Packing"];

            worksheetPackingView.Columns[2].Width = 600;

            for (int i = 0; i < DataList.Count; i++)
            {
                worksheetPackingThisMonth.Import(DataList[i].dataTableThisMonth, true, DataList[i].monthDataStartRowIndex, 1);
                worksheetPackingThisYear.Import(DataList[i].dataTableThisYear, true, DataList[i].yearDataStartRowIndex, 1);

                //写Month标准
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 6, 1].Value = "USL";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 7, 1].Value = "LSL";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 6, 1].Value = "USL";

                WritePackingStanard(DataList[i], 8, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 9, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 10, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 11, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 12, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 13, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 14, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 15, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 16, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WritePackingStanard(DataList[i], 17, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());


                WritePackingViewStandard(DataList[i], 4, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 5, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 6, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 7, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 8, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 9, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 10, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 11, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 12, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                WritePackingViewStandard(DataList[i], 13, DataList[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());

                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 5, 1].Value = "Count";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 0, 1].Value = "Cpk";

                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 5, 1].Value = "Count";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 1, 1].Value = "Max.";
                worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 0, 1].Value = "Cpk";


                for (int c = 8; c < 18; c++)
                {
                    Cell cellLT = worksheetPackingThisMonth[DataList[i].monthDataStartRowIndex + 1, c];
                    Cell cellRB = worksheetPackingThisMonth[DataList[i].monthDataStartRowIndex + 1 + DataList[i].dataTableThisMonth.Rows.Count - 1, c];
                    //count Month  COUNTA
                    string formulaCount = "COUNTA(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 5, c].Formula = formulaCount;
                    //avg Month
                    string formulaAvg = @"=IFERROR(AVERAGEIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">=0\"," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "),\"\")";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, c].ArrayFormula = formulaAvg;
                    Cell avg = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, c];
                    //max Month  =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMax = "=MAX(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 1, c].ArrayFormula = formulaMax;
                    Cell MAX = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, c];
                    //Min Month   =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMin = "=MIN(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 2, c].ArrayFormula = formulaMin;
                    //std Month    =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEV = "=IFERROR(STDEV(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")),\"\")";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEV;
                    //cpk   Month
                    string cellLSL = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSL = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVG = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStd = worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPK = "=IFERROR(IF(AND(" + cellUSL + "=\"\"," + cellLSL + "=\"\"),\"\",MIN((" + cellUSL + "-" + cellAVG + ")/3/" + cellStd + ",(" + cellAVG + "-" + cellLSL + ")/3/" + cellStd + ")),\"\")";
                    worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 0, c].ArrayFormula = formulaCPK;


                    string countMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetPackingThisMonth[DataList[i].monthDataEndRowIndex - 0, c].GetReferenceA1();


                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 4, c - 4, countMonthFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 5, c - 4, avgMonthFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 6, c - 4, STDEVMonthFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 7, c - 4, MinMonthFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 8, c - 4, MaxMonthFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 9, c - 4, CPKMonthFormula);



                    /////////////////////////////////////////////统计this Year
                    Cell cellLTYaer = worksheetPackingThisYear[DataList[i].yearDataStartRowIndex + 1, c];
                    Cell cellRBYaer = worksheetPackingThisYear[DataList[i].yearDataStartRowIndex + 1 + DataList[i].dataTableThisYear.Rows.Count - 1, c];
                    //count  COUNTA
                    string formulaCountYear = "COUNTA(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 5, c].Formula = formulaCountYear;
                    //avg Month
                    string formulaAvgYear = @"=IFERROR(AVERAGEIF(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ",\">=0\"," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "),\"\")";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, c].ArrayFormula = formulaAvgYear;
                    Cell avgYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, c];
                    //max Month     =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMaxYear = "=MAX(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 1, c].ArrayFormula = formulaMaxYear;
                    Cell MAXYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, c];
                    //Min Month    =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMinYear = "=MIN(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 2, c].ArrayFormula = formulaMinYear;
                    //std Month    =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEVYear = "=IFERROR(STDEV(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")),\"\")";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEVYear;
                    //cpk   Month
                    string cellLSLYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSLYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVGYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStdYear = worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                    string formulaCPKYear = "=IFERROR(IF(AND(" + cellUSLYear + "=\"\"," + cellLSLYear + "=\"\"),\"\",MIN((" + cellUSLYear + "-" + cellAVGYear + ")/3/" + cellStdYear + ",(" + cellAVGYear + "-" + cellLSLYear + ")/3/" + cellStdYear + ")),\"\")";
                    worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 0, c].ArrayFormula = formulaCPKYear;



                    string countYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetPackingThisYear[DataList[i].yearDataEndRowIndex - 0, c].GetReferenceA1();



                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 10, c - 4, countYearFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 11, c - 4, avgYearFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 12, c - 4, STDEVYearFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 13, c - 4, MinYearFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 14, c - 4, MaxYearFormula);
                    PackingWriteDataDetail(DataList[i].viewStartRowIndex + 15, c - 4, CPKYearFormula);


                }

                PackingDecorate(DataList[i], startDate, endDate);
                PackingWriteTitel(DataList[i], i);

            }




        }
        private void WritePackingStanard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetPackingView = workbook.Worksheets["3)Packing"];
            Worksheet worksheetPacking_ThisMonthData = workbook.Worksheets["Packing_ThisMonthData"];
            Worksheet worksheetPacking_ThisYearData = workbook.Worksheets["Packing_ThisYearData"];


            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetPacking_ThisMonthData[reportModel.monthDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                    worksheetPacking_ThisYearData[reportModel.yearDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetPacking_ThisMonthData[reportModel.monthDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                    worksheetPacking_ThisYearData[reportModel.yearDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void WritePackingViewStandard(DoMonthReportModel reportModel, int column, StandardSemi standard)
        {
            //IWorkbook workbook = spreadsheetControl1.Document;
            //Worksheet worksheetPackingView = workbook.Worksheets["3)Packing"];
            //Worksheet worksheetPacking_ThisMonthData = workbook.Worksheets["Packing_ThisMonthData"];
            //Worksheet worksheetPacking_ThisYearData = workbook.Worksheets["Packing_ThisYearData"];

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetPackingView = workbook.Worksheets["3)Packing"];
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetPackingView[reportModel.viewStartRowIndex + 2, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetPackingView[reportModel.viewStartRowIndex + 2 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void PackingWriteDataDetail(int row, int column, string formula)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["3)Packing"];
            worksheetDoView[row, column].Formula = formula;
        }

        private void PackingWriteTitel(DoMonthReportModel semiReport, int NO)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDO = workbook.Worksheets["3)Packing"];

            // 第一行  Unit    Grade   
            worksheetDO[semiReport.viewStartRowIndex, 0].Value = "Unit";
            worksheetDO[semiReport.viewStartRowIndex, 1].Value = "Grade";
            worksheetDO[semiReport.viewStartRowIndex, 2].Value = "Month";
            worksheetDO[semiReport.viewStartRowIndex, 3].Value = "Category";
            worksheetDO[semiReport.viewStartRowIndex, 4].Value = "IA(g/kg)";
            worksheetDO[semiReport.viewStartRowIndex, 5].Value = "DBP(ml/100g)";
            worksheetDO[semiReport.viewStartRowIndex, 6].Value = "IPH(gf)";
            worksheetDO[semiReport.viewStartRowIndex, 9].Value = "Fines(%)";
            worksheetDO[semiReport.viewStartRowIndex, 10].Value = "HL(%)";
            worksheetDO[semiReport.viewStartRowIndex, 11].Value = "Sieve Residue(ppm)";
            //第二行
            worksheetDO[semiReport.viewStartRowIndex + 1, 6].Value = "AVG";
            worksheetDO[semiReport.viewStartRowIndex + 1, 7].Value = "High";
            worksheetDO[semiReport.viewStartRowIndex + 1, 8].Value = "Low";
            worksheetDO[semiReport.viewStartRowIndex + 1, 11].Value = "#35";
            worksheetDO[semiReport.viewStartRowIndex + 1, 12].Value = "#100";
            worksheetDO[semiReport.viewStartRowIndex + 1, 13].Value = "#325";
            //合并单元格  横向 IPH     Sieve
            Range rangeIPH = worksheetDO.Range.FromLTRB(6, semiReport.viewStartRowIndex, 8, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeIPH);
            Range rangeSieve = worksheetDO.Range.FromLTRB(11, semiReport.viewStartRowIndex, 13, semiReport.viewStartRowIndex);
            worksheetDO.MergeCells(rangeSieve);
            //合并单元格 zongxiang
            int[] intArray = new int[] { 0, 1, 2, 3, 4, 5, 9, 10 };
            foreach (int i in intArray)
            {
                Range rangeUnit = worksheetDO.Range.FromLTRB(i, semiReport.viewStartRowIndex, i, semiReport.viewStartRowIndex + 1);
                worksheetDO.MergeCells(rangeUnit);
            }
            //标题第一行加高
            RowCollection rows = worksheetDO.Rows;
            Row row_byIndex = rows[semiReport.viewStartRowIndex];
            row_byIndex.RowHeight = 140;
            //字体加粗  居中

            //合并Unit 下方单元格   Grade下方单元格
            Range rangeUnitDetail = worksheetDO.Range.FromLTRB(0, semiReport.viewStartRowIndex + 2, 0, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Value = NO + 1;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 0].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            Range rangeGradeDetail = worksheetDO.Range.FromLTRB(1, semiReport.viewStartRowIndex + 2, 1, semiReport.viewStartRowIndex + 15);
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Value = semiReport.goodsName;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 1].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            worksheetDO.MergeCells(rangeUnitDetail);
            worksheetDO.MergeCells(rangeGradeDetail);
            //合并month下方 spec‘单元格
            Range rangeSpec = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 2, 2, semiReport.viewStartRowIndex + 3);
            worksheetDO.MergeCells(rangeSpec);
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Value = "spec'";
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 2, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 Month‘单元格
            Range rangeMonthCurrent = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 4, 2, semiReport.viewStartRowIndex + 9);
            worksheetDO.MergeCells(rangeMonthCurrent);
            // worksheetDO[semiReport.viewStartRowIndex + 4, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();       //当前月份
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 4, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 之前月份 ‘单元格
            Range rangeMonthBefore = worksheetDO.Range.FromLTRB(2, semiReport.viewStartRowIndex + 10, 2, semiReport.viewStartRowIndex + 15);
            worksheetDO.MergeCells(rangeMonthBefore);

            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetDO[semiReport.viewStartRowIndex + 10, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //Category
            worksheetDO[semiReport.viewStartRowIndex + 2, 3].Value = "LSL";
            worksheetDO[semiReport.viewStartRowIndex + 3, 3].Value = "USL";
            worksheetDO[semiReport.viewStartRowIndex + 4, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 5, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 6, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 7, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 8, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 9, 3].Value = "Cpk";

            worksheetDO[semiReport.viewStartRowIndex + 10, 3].Value = "Count";
            worksheetDO[semiReport.viewStartRowIndex + 11, 3].Value = "Avg.";
            worksheetDO[semiReport.viewStartRowIndex + 12, 3].Value = "Std.";
            worksheetDO[semiReport.viewStartRowIndex + 13, 3].Value = "Min.";
            worksheetDO[semiReport.viewStartRowIndex + 14, 3].Value = "Max.";
            worksheetDO[semiReport.viewStartRowIndex + 15, 3].Value = "Cpk";
        }

        private void PackingDecorate(DoMonthReportModel reportModel, DateTime startDate, DateTime endDate)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["3)Packing"];
            //加边框
            Range range = worksheetDoView.Range.FromLTRB(0, reportModel.viewStartRowIndex, 13, reportModel.viewStartRowIndex + 15);
            range.SetInsideBorders(Color.Black, BorderLineStyle.Dashed);
            range.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
            range.Font.Bold = true;

            Formatting rangeFormatting1 = range.BeginUpdateFormatting();
            rangeFormatting1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            range.EndUpdateFormatting(rangeFormatting1);


            //一年的数据加背景颜色
            Range rangeYear = worksheetDoView.Range.FromLTRB(2, reportModel.viewStartRowIndex + 10, 13, reportModel.viewStartRowIndex + 15);

            Formatting rangeFormatting = rangeYear.BeginUpdateFormatting();
            rangeFormatting.Fill.BackgroundColor = Color.FromArgb(204, 255, 204);
            rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            rangeYear.EndUpdateFormatting(rangeFormatting);

            worksheetDoView[reportModel.viewStartRowIndex + 5, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();

            worksheetDoView[reportModel.viewStartRowIndex + 11, 2].Value = new DateTime(startDate.Year, 01, 01).ToShortDateString() + "--" + endDate.ToShortDateString();
        }
        #endregion

        #region 出厂报告相关方法

        private void InitialShippingReport(DateTime startDate, DateTime endDate)
        {
            int startRowIndex = 1;
            int startRowIndexMonth = 0;
            int startRowIndexYear = 0;

            List<Good> goodsSemiList = db.Goods.Where(m => m.GoodsTypeID == CommonData.GoodsType_Production_ID).ToList();
            List<ShippingMonthReportModel> DoData = new List<ShippingMonthReportModel>();
            //string sql = "SELECT [Project52].[GoodsName] AS [GoodsName], [Project52].[CustomerName] AS [CustomerName], [Project52].[ReportProductNO] AS [ReportNO], [Project52].[LotNo] AS [LotNo], [Project52].[DateProduced] AS [DateProduced], [Project52].[ExPlant] AS [ExPlant], [Project52].[EmpName] AS [EmpName], CONVERT(float, [Project52].[C2] )AS [IA], CONVERT(float,[Project52].[C3]) AS [DBP], CONVERT(float,[Project52].[C4] )AS [IPH(AVG)], CONVERT(float,[Project52].[C5] )AS [IPH(High)], CONVERT(float,[Project52].[C6] )AS [IPH(Low)], CONVERT(float, [Project52].[C7] )AS [Fines], CONVERT(float, [Project52].[C8] )AS [HL], CONVERT(float,[Project52].[C9] )AS [Sieve Residue#35], CONVERT(float,[Project52].[C10]) AS [Sieve Residue#100], CONVERT(float,[Project52].[C11] )AS [Sieve Residue#325], CONVERT(float, [Project52].[C12] )AS [LT], CONVERT(float, [Project52].[C13]) AS [PD], CONVERT(float, [Project52].[C14] )AS [PH], CONVERT(float, [Project52].[C15]) AS [Tint], CONVERT(float, [Project52].[C16]) AS [CDBP], CONVERT(float, [Project52].[C17]) AS [N2SA], CONVERT(float, [Project52].[C18]) AS [Ash] FROM ( SELECT [Project51].[ReportProductNO] AS [ReportProductNO], [Project51].[LotNo] AS [LotNo], [Project51].[DateProduced] AS [DateProduced], [Project51].[ExPlant] AS [ExPlant], [Project51].[GoodsName] AS [GoodsName], [Project51].[CustomerName] AS [CustomerName], [Project51].[EmpName] AS [EmpName], 1 AS [C1], [Project51].[C1] AS [C2], [Project51].[C2] AS [C3], [Project51].[C3] AS [C4], [Project51].[C4] AS [C5], [Project51].[C5] AS [C6], [Project51].[C6] AS [C7], [Project51].[C7] AS [C8], [Project51].[C8] AS [C9], [Project51].[C9] AS [C10], [Project51].[C10] AS [C11], [Project51].[C11] AS [C12], [Project51].[C12] AS [C13], [Project51].[C13] AS [C14], [Project51].[C14] AS [C15], [Project51].[C15] AS [C16], [Project51].[C16] AS [C17], [Project51].[C17] AS [C18] FROM ( SELECT [Project49].[ReportProductID] AS [ReportProductID], [Project49].[ReportProductNO] AS [ReportProductNO], [Project49].[LotNo] AS [LotNo], [Project49].[DateProduced] AS [DateProduced], [Project49].[ExPlant] AS [ExPlant], [Project49].[GoodsName] AS [GoodsName], [Project49].[CustomerName] AS [CustomerName], [Project49].[EmpName] AS [EmpName], [Project49].[C1] AS [C1], [Project49].[C2] AS [C2], [Project49].[C3] AS [C3], [Project49].[C4] AS [C4], [Project49].[C5] AS [C5], [Project49].[C6] AS [C6], [Project49].[C7] AS [C7], [Project49].[C8] AS [C8], [Project49].[C9] AS [C9], [Project49].[C10] AS [C10], [Project49].[C11] AS [C11], [Project49].[C12] AS [C12], [Project49].[C13] AS [C13], [Project49].[C14] AS [C14], [Project49].[C15] AS [C15], [Project49].[C16] AS [C16], (SELECT TOP (1) [Extent21].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent21] WHERE ([Project49].[ReportProductID] = [Extent21].[ReportProductID]) AND ('27' = [Extent21].[TestItemID])) AS [C17] FROM ( SELECT [Project48].[ReportProductID] AS [ReportProductID], [Project48].[ReportProductNO] AS [ReportProductNO], [Project48].[LotNo] AS [LotNo], [Project48].[DateProduced] AS [DateProduced], [Project48].[ExPlant] AS [ExPlant], [Project48].[GoodsName] AS [GoodsName], [Project48].[CustomerName] AS [CustomerName], [Project48].[EmpName] AS [EmpName], [Project48].[C1] AS [C1], [Project48].[C2] AS [C2], [Project48].[C3] AS [C3], [Project48].[C4] AS [C4], [Project48].[C5] AS [C5], [Project48].[C6] AS [C6], [Project48].[C7] AS [C7], [Project48].[C8] AS [C8], [Project48].[C9] AS [C9], [Project48].[C10] AS [C10], [Project48].[C11] AS [C11], [Project48].[C12] AS [C12], [Project48].[C13] AS [C13], [Project48].[C14] AS [C14], [Project48].[C15] AS [C15], [Project48].[C16] AS [C16] FROM ( SELECT [Project46].[ReportProductID] AS [ReportProductID], [Project46].[ReportProductNO] AS [ReportProductNO], [Project46].[LotNo] AS [LotNo], [Project46].[DateProduced] AS [DateProduced], [Project46].[ExPlant] AS [ExPlant], [Project46].[GoodsName] AS [GoodsName], [Project46].[CustomerName] AS [CustomerName], [Project46].[EmpName] AS [EmpName], [Project46].[C1] AS [C1], [Project46].[C2] AS [C2], [Project46].[C3] AS [C3], [Project46].[C4] AS [C4], [Project46].[C5] AS [C5], [Project46].[C6] AS [C6], [Project46].[C7] AS [C7], [Project46].[C8] AS [C8], [Project46].[C9] AS [C9], [Project46].[C10] AS [C10], [Project46].[C11] AS [C11], [Project46].[C12] AS [C12], [Project46].[C13] AS [C13], [Project46].[C14] AS [C14], [Project46].[C15] AS [C15], (SELECT TOP (1) [Extent20].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent20] WHERE ([Project46].[ReportProductID] = [Extent20].[ReportProductID]) AND ('28' = [Extent20].[TestItemID])) AS [C16] FROM ( SELECT [Project45].[ReportProductID] AS [ReportProductID], [Project45].[ReportProductNO] AS [ReportProductNO], [Project45].[LotNo] AS [LotNo], [Project45].[DateProduced] AS [DateProduced], [Project45].[ExPlant] AS [ExPlant], [Project45].[GoodsName] AS [GoodsName], [Project45].[CustomerName] AS [CustomerName], [Project45].[EmpName] AS [EmpName], [Project45].[C1] AS [C1], [Project45].[C2] AS [C2], [Project45].[C3] AS [C3], [Project45].[C4] AS [C4], [Project45].[C5] AS [C5], [Project45].[C6] AS [C6], [Project45].[C7] AS [C7], [Project45].[C8] AS [C8], [Project45].[C9] AS [C9], [Project45].[C10] AS [C10], [Project45].[C11] AS [C11], [Project45].[C12] AS [C12], [Project45].[C13] AS [C13], [Project45].[C14] AS [C14], [Project45].[C15] AS [C15] FROM ( SELECT [Project43].[ReportProductID] AS [ReportProductID], [Project43].[ReportProductNO] AS [ReportProductNO], [Project43].[LotNo] AS [LotNo], [Project43].[DateProduced] AS [DateProduced], [Project43].[ExPlant] AS [ExPlant], [Project43].[GoodsName] AS [GoodsName], [Project43].[CustomerName] AS [CustomerName], [Project43].[EmpName] AS [EmpName], [Project43].[C1] AS [C1], [Project43].[C2] AS [C2], [Project43].[C3] AS [C3], [Project43].[C4] AS [C4], [Project43].[C5] AS [C5], [Project43].[C6] AS [C6], [Project43].[C7] AS [C7], [Project43].[C8] AS [C8], [Project43].[C9] AS [C9], [Project43].[C10] AS [C10], [Project43].[C11] AS [C11], [Project43].[C12] AS [C12], [Project43].[C13] AS [C13], [Project43].[C14] AS [C14], (SELECT TOP (1) [Extent19].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent19] WHERE ([Project43].[ReportProductID] = [Extent19].[ReportProductID]) AND ('26' = [Extent19].[TestItemID])) AS [C15] FROM ( SELECT [Project42].[ReportProductID] AS [ReportProductID], [Project42].[ReportProductNO] AS [ReportProductNO], [Project42].[LotNo] AS [LotNo], [Project42].[DateProduced] AS [DateProduced], [Project42].[ExPlant] AS [ExPlant], [Project42].[GoodsName] AS [GoodsName], [Project42].[CustomerName] AS [CustomerName], [Project42].[EmpName] AS [EmpName], [Project42].[C1] AS [C1], [Project42].[C2] AS [C2], [Project42].[C3] AS [C3], [Project42].[C4] AS [C4], [Project42].[C5] AS [C5], [Project42].[C6] AS [C6], [Project42].[C7] AS [C7], [Project42].[C8] AS [C8], [Project42].[C9] AS [C9], [Project42].[C10] AS [C10], [Project42].[C11] AS [C11], [Project42].[C12] AS [C12], [Project42].[C13] AS [C13], [Project42].[C14] AS [C14] FROM ( SELECT [Project40].[ReportProductID] AS [ReportProductID], [Project40].[ReportProductNO] AS [ReportProductNO], [Project40].[LotNo] AS [LotNo], [Project40].[DateProduced] AS [DateProduced], [Project40].[ExPlant] AS [ExPlant], [Project40].[GoodsName] AS [GoodsName], [Project40].[CustomerName] AS [CustomerName], [Project40].[EmpName] AS [EmpName], [Project40].[C1] AS [C1], [Project40].[C2] AS [C2], [Project40].[C3] AS [C3], [Project40].[C4] AS [C4], [Project40].[C5] AS [C5], [Project40].[C6] AS [C6], [Project40].[C7] AS [C7], [Project40].[C8] AS [C8], [Project40].[C9] AS [C9], [Project40].[C10] AS [C10], [Project40].[C11] AS [C11], [Project40].[C12] AS [C12], [Project40].[C13] AS [C13], (SELECT TOP (1) [Extent18].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent18] WHERE ([Project40].[ReportProductID] = [Extent18].[ReportProductID]) AND ('25' = [Extent18].[TestItemID])) AS [C14] FROM ( SELECT [Project39].[ReportProductID] AS [ReportProductID], [Project39].[ReportProductNO] AS [ReportProductNO], [Project39].[LotNo] AS [LotNo], [Project39].[DateProduced] AS [DateProduced], [Project39].[ExPlant] AS [ExPlant], [Project39].[GoodsName] AS [GoodsName], [Project39].[CustomerName] AS [CustomerName], [Project39].[EmpName] AS [EmpName], [Project39].[C1] AS [C1], [Project39].[C2] AS [C2], [Project39].[C3] AS [C3], [Project39].[C4] AS [C4], [Project39].[C5] AS [C5], [Project39].[C6] AS [C6], [Project39].[C7] AS [C7], [Project39].[C8] AS [C8], [Project39].[C9] AS [C9], [Project39].[C10] AS [C10], [Project39].[C11] AS [C11], [Project39].[C12] AS [C12], [Project39].[C13] AS [C13] FROM ( SELECT [Project37].[ReportProductID] AS [ReportProductID], [Project37].[ReportProductNO] AS [ReportProductNO], [Project37].[LotNo] AS [LotNo], [Project37].[DateProduced] AS [DateProduced], [Project37].[ExPlant] AS [ExPlant], [Project37].[GoodsName] AS [GoodsName], [Project37].[CustomerName] AS [CustomerName], [Project37].[EmpName] AS [EmpName], [Project37].[C1] AS [C1], [Project37].[C2] AS [C2], [Project37].[C3] AS [C3], [Project37].[C4] AS [C4], [Project37].[C5] AS [C5], [Project37].[C6] AS [C6], [Project37].[C7] AS [C7], [Project37].[C8] AS [C8], [Project37].[C9] AS [C9], [Project37].[C10] AS [C10], [Project37].[C11] AS [C11], [Project37].[C12] AS [C12], (SELECT TOP (1) [Extent17].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent17] WHERE ([Project37].[ReportProductID] = [Extent17].[ReportProductID]) AND ('17' = [Extent17].[TestItemID])) AS [C13] FROM ( SELECT [Project36].[ReportProductID] AS [ReportProductID], [Project36].[ReportProductNO] AS [ReportProductNO], [Project36].[LotNo] AS [LotNo], [Project36].[DateProduced] AS [DateProduced], [Project36].[ExPlant] AS [ExPlant], [Project36].[GoodsName] AS [GoodsName], [Project36].[CustomerName] AS [CustomerName], [Project36].[EmpName] AS [EmpName], [Project36].[C1] AS [C1], [Project36].[C2] AS [C2], [Project36].[C3] AS [C3], [Project36].[C4] AS [C4], [Project36].[C5] AS [C5], [Project36].[C6] AS [C6], [Project36].[C7] AS [C7], [Project36].[C8] AS [C8], [Project36].[C9] AS [C9], [Project36].[C10] AS [C10], [Project36].[C11] AS [C11], [Project36].[C12] AS [C12] FROM ( SELECT [Project34].[ReportProductID] AS [ReportProductID], [Project34].[ReportProductNO] AS [ReportProductNO], [Project34].[LotNo] AS [LotNo], [Project34].[DateProduced] AS [DateProduced], [Project34].[ExPlant] AS [ExPlant], [Project34].[GoodsName] AS [GoodsName], [Project34].[CustomerName] AS [CustomerName], [Project34].[EmpName] AS [EmpName], [Project34].[C1] AS [C1], [Project34].[C2] AS [C2], [Project34].[C3] AS [C3], [Project34].[C4] AS [C4], [Project34].[C5] AS [C5], [Project34].[C6] AS [C6], [Project34].[C7] AS [C7], [Project34].[C8] AS [C8], [Project34].[C9] AS [C9], [Project34].[C10] AS [C10], [Project34].[C11] AS [C11], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent16] WHERE ([Project34].[ReportProductID] = [Extent16].[ReportProductID]) AND ('16' = [Extent16].[TestItemID])) AS [C12] FROM ( SELECT [Project33].[ReportProductID] AS [ReportProductID], [Project33].[ReportProductNO] AS [ReportProductNO], [Project33].[LotNo] AS [LotNo], [Project33].[DateProduced] AS [DateProduced], [Project33].[ExPlant] AS [ExPlant], [Project33].[GoodsName] AS [GoodsName], [Project33].[CustomerName] AS [CustomerName], [Project33].[EmpName] AS [EmpName], [Project33].[C1] AS [C1], [Project33].[C2] AS [C2], [Project33].[C3] AS [C3], [Project33].[C4] AS [C4], [Project33].[C5] AS [C5], [Project33].[C6] AS [C6], [Project33].[C7] AS [C7], [Project33].[C8] AS [C8], [Project33].[C9] AS [C9], [Project33].[C10] AS [C10], [Project33].[C11] AS [C11] FROM ( SELECT [Project31].[ReportProductID] AS [ReportProductID], [Project31].[ReportProductNO] AS [ReportProductNO], [Project31].[LotNo] AS [LotNo], [Project31].[DateProduced] AS [DateProduced], [Project31].[ExPlant] AS [ExPlant], [Project31].[GoodsName] AS [GoodsName], [Project31].[CustomerName] AS [CustomerName], [Project31].[EmpName] AS [EmpName], [Project31].[C1] AS [C1], [Project31].[C2] AS [C2], [Project31].[C3] AS [C3], [Project31].[C4] AS [C4], [Project31].[C5] AS [C5], [Project31].[C6] AS [C6], [Project31].[C7] AS [C7], [Project31].[C8] AS [C8], [Project31].[C9] AS [C9], [Project31].[C10] AS [C10], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent15] WHERE ([Project31].[ReportProductID] = [Extent15].[ReportProductID]) AND ('15' = [Extent15].[TestItemID])) AS [C11] FROM ( SELECT [Project30].[ReportProductID] AS [ReportProductID], [Project30].[ReportProductNO] AS [ReportProductNO], [Project30].[LotNo] AS [LotNo], [Project30].[DateProduced] AS [DateProduced], [Project30].[ExPlant] AS [ExPlant], [Project30].[GoodsName] AS [GoodsName], [Project30].[CustomerName] AS [CustomerName], [Project30].[EmpName] AS [EmpName], [Project30].[C1] AS [C1], [Project30].[C2] AS [C2], [Project30].[C3] AS [C3], [Project30].[C4] AS [C4], [Project30].[C5] AS [C5], [Project30].[C6] AS [C6], [Project30].[C7] AS [C7], [Project30].[C8] AS [C8], [Project30].[C9] AS [C9], [Project30].[C10] AS [C10] FROM ( SELECT [Project28].[ReportProductID] AS [ReportProductID], [Project28].[ReportProductNO] AS [ReportProductNO], [Project28].[LotNo] AS [LotNo], [Project28].[DateProduced] AS [DateProduced], [Project28].[ExPlant] AS [ExPlant], [Project28].[GoodsName] AS [GoodsName], [Project28].[CustomerName] AS [CustomerName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent14] WHERE ([Project28].[ReportProductID] = [Extent14].[ReportProductID]) AND ('14' = [Extent14].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportProductID] AS [ReportProductID], [Project27].[ReportProductNO] AS [ReportProductNO], [Project27].[LotNo] AS [LotNo], [Project27].[DateProduced] AS [DateProduced], [Project27].[ExPlant] AS [ExPlant], [Project27].[GoodsName] AS [GoodsName], [Project27].[CustomerName] AS [CustomerName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportProductID] AS [ReportProductID], [Project25].[ReportProductNO] AS [ReportProductNO], [Project25].[LotNo] AS [LotNo], [Project25].[DateProduced] AS [DateProduced], [Project25].[ExPlant] AS [ExPlant], [Project25].[GoodsName] AS [GoodsName], [Project25].[CustomerName] AS [CustomerName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent13] WHERE ([Project25].[ReportProductID] = [Extent13].[ReportProductID]) AND ('13' = [Extent13].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportProductID] AS [ReportProductID], [Project24].[ReportProductNO] AS [ReportProductNO], [Project24].[LotNo] AS [LotNo], [Project24].[DateProduced] AS [DateProduced], [Project24].[ExPlant] AS [ExPlant], [Project24].[GoodsName] AS [GoodsName], [Project24].[CustomerName] AS [CustomerName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportProductID] AS [ReportProductID], [Project22].[ReportProductNO] AS [ReportProductNO], [Project22].[LotNo] AS [LotNo], [Project22].[DateProduced] AS [DateProduced], [Project22].[ExPlant] AS [ExPlant], [Project22].[GoodsName] AS [GoodsName], [Project22].[CustomerName] AS [CustomerName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent12] WHERE ([Project22].[ReportProductID] = [Extent12].[ReportProductID]) AND ('12' = [Extent12].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportProductID] AS [ReportProductID], [Project21].[ReportProductNO] AS [ReportProductNO], [Project21].[LotNo] AS [LotNo], [Project21].[DateProduced] AS [DateProduced], [Project21].[ExPlant] AS [ExPlant], [Project21].[GoodsName] AS [GoodsName], [Project21].[CustomerName] AS [CustomerName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportProductID] AS [ReportProductID], [Project19].[ReportProductNO] AS [ReportProductNO], [Project19].[LotNo] AS [LotNo], [Project19].[DateProduced] AS [DateProduced], [Project19].[ExPlant] AS [ExPlant], [Project19].[GoodsName] AS [GoodsName], [Project19].[CustomerName] AS [CustomerName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent11] WHERE ([Project19].[ReportProductID] = [Extent11].[ReportProductID]) AND ('10' = [Extent11].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportProductID] AS [ReportProductID], [Project18].[ReportProductNO] AS [ReportProductNO], [Project18].[LotNo] AS [LotNo], [Project18].[DateProduced] AS [DateProduced], [Project18].[ExPlant] AS [ExPlant], [Project18].[GoodsName] AS [GoodsName], [Project18].[CustomerName] AS [CustomerName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportProductID] AS [ReportProductID], [Project16].[ReportProductNO] AS [ReportProductNO], [Project16].[LotNo] AS [LotNo], [Project16].[DateProduced] AS [DateProduced], [Project16].[ExPlant] AS [ExPlant], [Project16].[GoodsName] AS [GoodsName], [Project16].[CustomerName] AS [CustomerName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent10] WHERE ([Project16].[ReportProductID] = [Extent10].[ReportProductID]) AND ('9' = [Extent10].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportProductID] AS [ReportProductID], [Project15].[ReportProductNO] AS [ReportProductNO], [Project15].[LotNo] AS [LotNo], [Project15].[DateProduced] AS [DateProduced], [Project15].[ExPlant] AS [ExPlant], [Project15].[GoodsName] AS [GoodsName], [Project15].[CustomerName] AS [CustomerName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportProductID] AS [ReportProductID], [Project13].[ReportProductNO] AS [ReportProductNO], [Project13].[LotNo] AS [LotNo], [Project13].[DateProduced] AS [DateProduced], [Project13].[ExPlant] AS [ExPlant], [Project13].[GoodsName] AS [GoodsName], [Project13].[CustomerName] AS [CustomerName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent9] WHERE ([Project13].[ReportProductID] = [Extent9].[ReportProductID]) AND ('30' = [Extent9].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportProductID] AS [ReportProductID], [Project12].[ReportProductNO] AS [ReportProductNO], [Project12].[LotNo] AS [LotNo], [Project12].[DateProduced] AS [DateProduced], [Project12].[ExPlant] AS [ExPlant], [Project12].[GoodsName] AS [GoodsName], [Project12].[CustomerName] AS [CustomerName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportProductID] AS [ReportProductID], [Project10].[ReportProductNO] AS [ReportProductNO], [Project10].[LotNo] AS [LotNo], [Project10].[DateProduced] AS [DateProduced], [Project10].[ExPlant] AS [ExPlant], [Project10].[GoodsName] AS [GoodsName], [Project10].[CustomerName] AS [CustomerName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent8] WHERE ([Project10].[ReportProductID] = [Extent8].[ReportProductID]) AND ('8' = [Extent8].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportProductID] AS [ReportProductID], [Project9].[ReportProductNO] AS [ReportProductNO], [Project9].[LotNo] AS [LotNo], [Project9].[DateProduced] AS [DateProduced], [Project9].[ExPlant] AS [ExPlant], [Project9].[GoodsName] AS [GoodsName], [Project9].[CustomerName] AS [CustomerName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportProductID] AS [ReportProductID], [Project7].[ReportProductNO] AS [ReportProductNO], [Project7].[LotNo] AS [LotNo], [Project7].[DateProduced] AS [DateProduced], [Project7].[ExPlant] AS [ExPlant], [Project7].[GoodsName] AS [GoodsName], [Project7].[CustomerName] AS [CustomerName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent7] WHERE ([Project7].[ReportProductID] = [Extent7].[ReportProductID]) AND ('46' = [Extent7].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportProductID] AS [ReportProductID], [Project6].[ReportProductNO] AS [ReportProductNO], [Project6].[LotNo] AS [LotNo], [Project6].[DateProduced] AS [DateProduced], [Project6].[ExPlant] AS [ExPlant], [Project6].[GoodsName] AS [GoodsName], [Project6].[CustomerName] AS [CustomerName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportProductID] AS [ReportProductID], [Project4].[ReportProductNO] AS [ReportProductNO], [Project4].[LotNo] AS [LotNo], [Project4].[DateProduced] AS [DateProduced], [Project4].[ExPlant] AS [ExPlant], [Project4].[GoodsName] AS [GoodsName], [Project4].[CustomerName] AS [CustomerName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent6].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent6] WHERE ([Project4].[ReportProductID] = [Extent6].[ReportProductID]) AND ('7' = [Extent6].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportProductID] AS [ReportProductID], [Project3].[ReportProductNO] AS [ReportProductNO], [Project3].[LotNo] AS [LotNo], [Project3].[DateProduced] AS [DateProduced], [Project3].[ExPlant] AS [ExPlant], [Project3].[GoodsName] AS [GoodsName], [Project3].[CustomerName] AS [CustomerName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportProductID] AS [ReportProductID], [Project1].[ReportProductNO] AS [ReportProductNO], [Project1].[LotNo] AS [LotNo], [Project1].[DateProduced] AS [DateProduced], [Project1].[ExPlant] AS [ExPlant], [Project1].[GoodsName] AS [GoodsName], [Project1].[CustomerName] AS [CustomerName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent5] WHERE ([Project1].[ReportProductID] = [Extent5].[ReportProductID]) AND ('1' = [Extent5].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportProductID] AS [ReportProductID], [Filter1].[ReportProductNO] AS [ReportProductNO], [Filter1].[LotNo] AS [LotNo], [Filter1].[DateProduced] AS [DateProduced], [Filter1].[ExPlant] AS [ExPlant], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[CustomerName] AS [CustomerName], [Extent4].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportProductID] AS [ReportProductID], [Extent1].[ReportProductNO] AS [ReportProductNO], [Extent1].[LotNo] AS [LotNo], [Extent1].[DateProduced] AS [DateProduced], [Extent1].[ExPlant] AS [ExPlant], [Extent1].[LoginUserID] AS [LoginUserID], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[CustomerName] AS [CustomerName] FROM [dbo].[ReportProducts] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] LEFT OUTER JOIN [dbo].[Customers] AS [Extent3] ON [Extent1].[CustomerID] = [Extent3].[CustomerID] WHERE @GoodsID = [Extent1].[GoodsID] ) AS [Filter1] LEFT OUTER JOIN [dbo].[LoginUsers] AS [Extent4] ON [Filter1].[LoginUserID] = [Extent4].[LoginUserID] WHERE ([Filter1].[DateProduced] <= @EndDate) AND ([Filter1].[DateProduced] >= @StartDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ) AS [Project33] ) AS [Project34] ) AS [Project36] ) AS [Project37] ) AS [Project39] ) AS [Project40] ) AS [Project42] ) AS [Project43] ) AS [Project45] ) AS [Project46] ) AS [Project48] ) AS [Project49] ) AS [Project51] ) AS [Project52] ORDER BY [Project52].[DateProduced] ASC";
            string sql = "SELECT [Project52].[GoodsName] AS [GoodsName], [Project52].[CustomerName] AS [CustomerName], [Project52].[ReportProductNO] AS [ReportNO], [Project52].[LotNo] AS [LotNo], [Project52].[DateProduced] AS [DateProduced], [Project52].[ExPlant] AS [ExPlant], [Project52].[EmpName] AS [EmpName], CASE [Project52].[C2] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C2] ) END AS [IA], CASE [Project52].[C3] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C3] ) END AS [DBP], CASE [Project52].[C4] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C4] ) END AS [IPH(AVG)], CASE [Project52].[C5] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C5] ) END AS [IPH(Gigh)], CASE [Project52].[C6] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C6] ) END AS [IPH(Low)], CASE [Project52].[C7] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C7] ) END AS [Fines], CASE [Project52].[C8] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C8] ) END AS [HL], CASE [Project52].[C9] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C9] ) END AS [Sieve Residue(#35)], CASE [Project52].[C10] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C10]) END AS [Sieve Residue(#100)], CASE [Project52].[C11] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C11]) END AS [Sieve Residue(#325)], CASE [Project52].[C12] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C12]) END AS [LT], CASE [Project52].[C13] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C13]) END AS [PD], CASE [Project52].[C14] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C14]) END AS [PH], CASE [Project52].[C15] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C15]) END AS [Tint], CASE [Project52].[C16] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C16]) END AS [CDBP], CASE [Project52].[C17] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C17]) END AS [N2SA], CASE [Project52].[C18] WHEN '' THEN NUll ELSE CONVERT(float,[Project52].[C18]) END AS [Ash] FROM ( SELECT [Project51].[ReportProductNO] AS [ReportProductNO], [Project51].[LotNo] AS [LotNo], [Project51].[DateProduced] AS [DateProduced], [Project51].[ExPlant] AS [ExPlant], [Project51].[GoodsName] AS [GoodsName], [Project51].[CustomerName] AS [CustomerName], [Project51].[EmpName] AS [EmpName], 1 AS [C1], [Project51].[C1] AS [C2], [Project51].[C2] AS [C3], [Project51].[C3] AS [C4], [Project51].[C4] AS [C5], [Project51].[C5] AS [C6], [Project51].[C6] AS [C7], [Project51].[C7] AS [C8], [Project51].[C8] AS [C9], [Project51].[C9] AS [C10], [Project51].[C10] AS [C11], [Project51].[C11] AS [C12], [Project51].[C12] AS [C13], [Project51].[C13] AS [C14], [Project51].[C14] AS [C15], [Project51].[C15] AS [C16], [Project51].[C16] AS [C17], [Project51].[C17] AS [C18] FROM ( SELECT [Project49].[ReportProductID] AS [ReportProductID], [Project49].[ReportProductNO] AS [ReportProductNO], [Project49].[LotNo] AS [LotNo], [Project49].[DateProduced] AS [DateProduced], [Project49].[ExPlant] AS [ExPlant], [Project49].[GoodsName] AS [GoodsName], [Project49].[CustomerName] AS [CustomerName], [Project49].[EmpName] AS [EmpName], [Project49].[C1] AS [C1], [Project49].[C2] AS [C2], [Project49].[C3] AS [C3], [Project49].[C4] AS [C4], [Project49].[C5] AS [C5], [Project49].[C6] AS [C6], [Project49].[C7] AS [C7], [Project49].[C8] AS [C8], [Project49].[C9] AS [C9], [Project49].[C10] AS [C10], [Project49].[C11] AS [C11], [Project49].[C12] AS [C12], [Project49].[C13] AS [C13], [Project49].[C14] AS [C14], [Project49].[C15] AS [C15], [Project49].[C16] AS [C16], (SELECT TOP (1) [Extent21].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent21] WHERE ([Project49].[ReportProductID] = [Extent21].[ReportProductID]) AND ('27' = [Extent21].[TestItemID])) AS [C17] FROM ( SELECT [Project48].[ReportProductID] AS [ReportProductID], [Project48].[ReportProductNO] AS [ReportProductNO], [Project48].[LotNo] AS [LotNo], [Project48].[DateProduced] AS [DateProduced], [Project48].[ExPlant] AS [ExPlant], [Project48].[GoodsName] AS [GoodsName], [Project48].[CustomerName] AS [CustomerName], [Project48].[EmpName] AS [EmpName], [Project48].[C1] AS [C1], [Project48].[C2] AS [C2], [Project48].[C3] AS [C3], [Project48].[C4] AS [C4], [Project48].[C5] AS [C5], [Project48].[C6] AS [C6], [Project48].[C7] AS [C7], [Project48].[C8] AS [C8], [Project48].[C9] AS [C9], [Project48].[C10] AS [C10], [Project48].[C11] AS [C11], [Project48].[C12] AS [C12], [Project48].[C13] AS [C13], [Project48].[C14] AS [C14], [Project48].[C15] AS [C15], [Project48].[C16] AS [C16] FROM ( SELECT [Project46].[ReportProductID] AS [ReportProductID], [Project46].[ReportProductNO] AS [ReportProductNO], [Project46].[LotNo] AS [LotNo], [Project46].[DateProduced] AS [DateProduced], [Project46].[ExPlant] AS [ExPlant], [Project46].[GoodsName] AS [GoodsName], [Project46].[CustomerName] AS [CustomerName], [Project46].[EmpName] AS [EmpName], [Project46].[C1] AS [C1], [Project46].[C2] AS [C2], [Project46].[C3] AS [C3], [Project46].[C4] AS [C4], [Project46].[C5] AS [C5], [Project46].[C6] AS [C6], [Project46].[C7] AS [C7], [Project46].[C8] AS [C8], [Project46].[C9] AS [C9], [Project46].[C10] AS [C10], [Project46].[C11] AS [C11], [Project46].[C12] AS [C12], [Project46].[C13] AS [C13], [Project46].[C14] AS [C14], [Project46].[C15] AS [C15], (SELECT TOP (1) [Extent20].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent20] WHERE ([Project46].[ReportProductID] = [Extent20].[ReportProductID]) AND ('28' = [Extent20].[TestItemID])) AS [C16] FROM ( SELECT [Project45].[ReportProductID] AS [ReportProductID], [Project45].[ReportProductNO] AS [ReportProductNO], [Project45].[LotNo] AS [LotNo], [Project45].[DateProduced] AS [DateProduced], [Project45].[ExPlant] AS [ExPlant], [Project45].[GoodsName] AS [GoodsName], [Project45].[CustomerName] AS [CustomerName], [Project45].[EmpName] AS [EmpName], [Project45].[C1] AS [C1], [Project45].[C2] AS [C2], [Project45].[C3] AS [C3], [Project45].[C4] AS [C4], [Project45].[C5] AS [C5], [Project45].[C6] AS [C6], [Project45].[C7] AS [C7], [Project45].[C8] AS [C8], [Project45].[C9] AS [C9], [Project45].[C10] AS [C10], [Project45].[C11] AS [C11], [Project45].[C12] AS [C12], [Project45].[C13] AS [C13], [Project45].[C14] AS [C14], [Project45].[C15] AS [C15] FROM ( SELECT [Project43].[ReportProductID] AS [ReportProductID], [Project43].[ReportProductNO] AS [ReportProductNO], [Project43].[LotNo] AS [LotNo], [Project43].[DateProduced] AS [DateProduced], [Project43].[ExPlant] AS [ExPlant], [Project43].[GoodsName] AS [GoodsName], [Project43].[CustomerName] AS [CustomerName], [Project43].[EmpName] AS [EmpName], [Project43].[C1] AS [C1], [Project43].[C2] AS [C2], [Project43].[C3] AS [C3], [Project43].[C4] AS [C4], [Project43].[C5] AS [C5], [Project43].[C6] AS [C6], [Project43].[C7] AS [C7], [Project43].[C8] AS [C8], [Project43].[C9] AS [C9], [Project43].[C10] AS [C10], [Project43].[C11] AS [C11], [Project43].[C12] AS [C12], [Project43].[C13] AS [C13], [Project43].[C14] AS [C14], (SELECT TOP (1) [Extent19].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent19] WHERE ([Project43].[ReportProductID] = [Extent19].[ReportProductID]) AND ('26' = [Extent19].[TestItemID])) AS [C15] FROM ( SELECT [Project42].[ReportProductID] AS [ReportProductID], [Project42].[ReportProductNO] AS [ReportProductNO], [Project42].[LotNo] AS [LotNo], [Project42].[DateProduced] AS [DateProduced], [Project42].[ExPlant] AS [ExPlant], [Project42].[GoodsName] AS [GoodsName], [Project42].[CustomerName] AS [CustomerName], [Project42].[EmpName] AS [EmpName], [Project42].[C1] AS [C1], [Project42].[C2] AS [C2], [Project42].[C3] AS [C3], [Project42].[C4] AS [C4], [Project42].[C5] AS [C5], [Project42].[C6] AS [C6], [Project42].[C7] AS [C7], [Project42].[C8] AS [C8], [Project42].[C9] AS [C9], [Project42].[C10] AS [C10], [Project42].[C11] AS [C11], [Project42].[C12] AS [C12], [Project42].[C13] AS [C13], [Project42].[C14] AS [C14] FROM ( SELECT [Project40].[ReportProductID] AS [ReportProductID], [Project40].[ReportProductNO] AS [ReportProductNO], [Project40].[LotNo] AS [LotNo], [Project40].[DateProduced] AS [DateProduced], [Project40].[ExPlant] AS [ExPlant], [Project40].[GoodsName] AS [GoodsName], [Project40].[CustomerName] AS [CustomerName], [Project40].[EmpName] AS [EmpName], [Project40].[C1] AS [C1], [Project40].[C2] AS [C2], [Project40].[C3] AS [C3], [Project40].[C4] AS [C4], [Project40].[C5] AS [C5], [Project40].[C6] AS [C6], [Project40].[C7] AS [C7], [Project40].[C8] AS [C8], [Project40].[C9] AS [C9], [Project40].[C10] AS [C10], [Project40].[C11] AS [C11], [Project40].[C12] AS [C12], [Project40].[C13] AS [C13], (SELECT TOP (1) [Extent18].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent18] WHERE ([Project40].[ReportProductID] = [Extent18].[ReportProductID]) AND ('25' = [Extent18].[TestItemID])) AS [C14] FROM ( SELECT [Project39].[ReportProductID] AS [ReportProductID], [Project39].[ReportProductNO] AS [ReportProductNO], [Project39].[LotNo] AS [LotNo], [Project39].[DateProduced] AS [DateProduced], [Project39].[ExPlant] AS [ExPlant], [Project39].[GoodsName] AS [GoodsName], [Project39].[CustomerName] AS [CustomerName], [Project39].[EmpName] AS [EmpName], [Project39].[C1] AS [C1], [Project39].[C2] AS [C2], [Project39].[C3] AS [C3], [Project39].[C4] AS [C4], [Project39].[C5] AS [C5], [Project39].[C6] AS [C6], [Project39].[C7] AS [C7], [Project39].[C8] AS [C8], [Project39].[C9] AS [C9], [Project39].[C10] AS [C10], [Project39].[C11] AS [C11], [Project39].[C12] AS [C12], [Project39].[C13] AS [C13] FROM ( SELECT [Project37].[ReportProductID] AS [ReportProductID], [Project37].[ReportProductNO] AS [ReportProductNO], [Project37].[LotNo] AS [LotNo], [Project37].[DateProduced] AS [DateProduced], [Project37].[ExPlant] AS [ExPlant], [Project37].[GoodsName] AS [GoodsName], [Project37].[CustomerName] AS [CustomerName], [Project37].[EmpName] AS [EmpName], [Project37].[C1] AS [C1], [Project37].[C2] AS [C2], [Project37].[C3] AS [C3], [Project37].[C4] AS [C4], [Project37].[C5] AS [C5], [Project37].[C6] AS [C6], [Project37].[C7] AS [C7], [Project37].[C8] AS [C8], [Project37].[C9] AS [C9], [Project37].[C10] AS [C10], [Project37].[C11] AS [C11], [Project37].[C12] AS [C12], (SELECT TOP (1) [Extent17].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent17] WHERE ([Project37].[ReportProductID] = [Extent17].[ReportProductID]) AND ('17' = [Extent17].[TestItemID])) AS [C13] FROM ( SELECT [Project36].[ReportProductID] AS [ReportProductID], [Project36].[ReportProductNO] AS [ReportProductNO], [Project36].[LotNo] AS [LotNo], [Project36].[DateProduced] AS [DateProduced], [Project36].[ExPlant] AS [ExPlant], [Project36].[GoodsName] AS [GoodsName], [Project36].[CustomerName] AS [CustomerName], [Project36].[EmpName] AS [EmpName], [Project36].[C1] AS [C1], [Project36].[C2] AS [C2], [Project36].[C3] AS [C3], [Project36].[C4] AS [C4], [Project36].[C5] AS [C5], [Project36].[C6] AS [C6], [Project36].[C7] AS [C7], [Project36].[C8] AS [C8], [Project36].[C9] AS [C9], [Project36].[C10] AS [C10], [Project36].[C11] AS [C11], [Project36].[C12] AS [C12] FROM ( SELECT [Project34].[ReportProductID] AS [ReportProductID], [Project34].[ReportProductNO] AS [ReportProductNO], [Project34].[LotNo] AS [LotNo], [Project34].[DateProduced] AS [DateProduced], [Project34].[ExPlant] AS [ExPlant], [Project34].[GoodsName] AS [GoodsName], [Project34].[CustomerName] AS [CustomerName], [Project34].[EmpName] AS [EmpName], [Project34].[C1] AS [C1], [Project34].[C2] AS [C2], [Project34].[C3] AS [C3], [Project34].[C4] AS [C4], [Project34].[C5] AS [C5], [Project34].[C6] AS [C6], [Project34].[C7] AS [C7], [Project34].[C8] AS [C8], [Project34].[C9] AS [C9], [Project34].[C10] AS [C10], [Project34].[C11] AS [C11], (SELECT TOP (1) [Extent16].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent16] WHERE ([Project34].[ReportProductID] = [Extent16].[ReportProductID]) AND ('16' = [Extent16].[TestItemID])) AS [C12] FROM ( SELECT [Project33].[ReportProductID] AS [ReportProductID], [Project33].[ReportProductNO] AS [ReportProductNO], [Project33].[LotNo] AS [LotNo], [Project33].[DateProduced] AS [DateProduced], [Project33].[ExPlant] AS [ExPlant], [Project33].[GoodsName] AS [GoodsName], [Project33].[CustomerName] AS [CustomerName], [Project33].[EmpName] AS [EmpName], [Project33].[C1] AS [C1], [Project33].[C2] AS [C2], [Project33].[C3] AS [C3], [Project33].[C4] AS [C4], [Project33].[C5] AS [C5], [Project33].[C6] AS [C6], [Project33].[C7] AS [C7], [Project33].[C8] AS [C8], [Project33].[C9] AS [C9], [Project33].[C10] AS [C10], [Project33].[C11] AS [C11] FROM ( SELECT [Project31].[ReportProductID] AS [ReportProductID], [Project31].[ReportProductNO] AS [ReportProductNO], [Project31].[LotNo] AS [LotNo], [Project31].[DateProduced] AS [DateProduced], [Project31].[ExPlant] AS [ExPlant], [Project31].[GoodsName] AS [GoodsName], [Project31].[CustomerName] AS [CustomerName], [Project31].[EmpName] AS [EmpName], [Project31].[C1] AS [C1], [Project31].[C2] AS [C2], [Project31].[C3] AS [C3], [Project31].[C4] AS [C4], [Project31].[C5] AS [C5], [Project31].[C6] AS [C6], [Project31].[C7] AS [C7], [Project31].[C8] AS [C8], [Project31].[C9] AS [C9], [Project31].[C10] AS [C10], (SELECT TOP (1) [Extent15].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent15] WHERE ([Project31].[ReportProductID] = [Extent15].[ReportProductID]) AND ('15' = [Extent15].[TestItemID])) AS [C11] FROM ( SELECT [Project30].[ReportProductID] AS [ReportProductID], [Project30].[ReportProductNO] AS [ReportProductNO], [Project30].[LotNo] AS [LotNo], [Project30].[DateProduced] AS [DateProduced], [Project30].[ExPlant] AS [ExPlant], [Project30].[GoodsName] AS [GoodsName], [Project30].[CustomerName] AS [CustomerName], [Project30].[EmpName] AS [EmpName], [Project30].[C1] AS [C1], [Project30].[C2] AS [C2], [Project30].[C3] AS [C3], [Project30].[C4] AS [C4], [Project30].[C5] AS [C5], [Project30].[C6] AS [C6], [Project30].[C7] AS [C7], [Project30].[C8] AS [C8], [Project30].[C9] AS [C9], [Project30].[C10] AS [C10] FROM ( SELECT [Project28].[ReportProductID] AS [ReportProductID], [Project28].[ReportProductNO] AS [ReportProductNO], [Project28].[LotNo] AS [LotNo], [Project28].[DateProduced] AS [DateProduced], [Project28].[ExPlant] AS [ExPlant], [Project28].[GoodsName] AS [GoodsName], [Project28].[CustomerName] AS [CustomerName], [Project28].[EmpName] AS [EmpName], [Project28].[C1] AS [C1], [Project28].[C2] AS [C2], [Project28].[C3] AS [C3], [Project28].[C4] AS [C4], [Project28].[C5] AS [C5], [Project28].[C6] AS [C6], [Project28].[C7] AS [C7], [Project28].[C8] AS [C8], [Project28].[C9] AS [C9], (SELECT TOP (1) [Extent14].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent14] WHERE ([Project28].[ReportProductID] = [Extent14].[ReportProductID]) AND ('14' = [Extent14].[TestItemID])) AS [C10] FROM ( SELECT [Project27].[ReportProductID] AS [ReportProductID], [Project27].[ReportProductNO] AS [ReportProductNO], [Project27].[LotNo] AS [LotNo], [Project27].[DateProduced] AS [DateProduced], [Project27].[ExPlant] AS [ExPlant], [Project27].[GoodsName] AS [GoodsName], [Project27].[CustomerName] AS [CustomerName], [Project27].[EmpName] AS [EmpName], [Project27].[C1] AS [C1], [Project27].[C2] AS [C2], [Project27].[C3] AS [C3], [Project27].[C4] AS [C4], [Project27].[C5] AS [C5], [Project27].[C6] AS [C6], [Project27].[C7] AS [C7], [Project27].[C8] AS [C8], [Project27].[C9] AS [C9] FROM ( SELECT [Project25].[ReportProductID] AS [ReportProductID], [Project25].[ReportProductNO] AS [ReportProductNO], [Project25].[LotNo] AS [LotNo], [Project25].[DateProduced] AS [DateProduced], [Project25].[ExPlant] AS [ExPlant], [Project25].[GoodsName] AS [GoodsName], [Project25].[CustomerName] AS [CustomerName], [Project25].[EmpName] AS [EmpName], [Project25].[C1] AS [C1], [Project25].[C2] AS [C2], [Project25].[C3] AS [C3], [Project25].[C4] AS [C4], [Project25].[C5] AS [C5], [Project25].[C6] AS [C6], [Project25].[C7] AS [C7], [Project25].[C8] AS [C8], (SELECT TOP (1) [Extent13].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent13] WHERE ([Project25].[ReportProductID] = [Extent13].[ReportProductID]) AND ('13' = [Extent13].[TestItemID])) AS [C9] FROM ( SELECT [Project24].[ReportProductID] AS [ReportProductID], [Project24].[ReportProductNO] AS [ReportProductNO], [Project24].[LotNo] AS [LotNo], [Project24].[DateProduced] AS [DateProduced], [Project24].[ExPlant] AS [ExPlant], [Project24].[GoodsName] AS [GoodsName], [Project24].[CustomerName] AS [CustomerName], [Project24].[EmpName] AS [EmpName], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3], [Project24].[C4] AS [C4], [Project24].[C5] AS [C5], [Project24].[C6] AS [C6], [Project24].[C7] AS [C7], [Project24].[C8] AS [C8] FROM ( SELECT [Project22].[ReportProductID] AS [ReportProductID], [Project22].[ReportProductNO] AS [ReportProductNO], [Project22].[LotNo] AS [LotNo], [Project22].[DateProduced] AS [DateProduced], [Project22].[ExPlant] AS [ExPlant], [Project22].[GoodsName] AS [GoodsName], [Project22].[CustomerName] AS [CustomerName], [Project22].[EmpName] AS [EmpName], [Project22].[C1] AS [C1], [Project22].[C2] AS [C2], [Project22].[C3] AS [C3], [Project22].[C4] AS [C4], [Project22].[C5] AS [C5], [Project22].[C6] AS [C6], [Project22].[C7] AS [C7], (SELECT TOP (1) [Extent12].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent12] WHERE ([Project22].[ReportProductID] = [Extent12].[ReportProductID]) AND ('12' = [Extent12].[TestItemID])) AS [C8] FROM ( SELECT [Project21].[ReportProductID] AS [ReportProductID], [Project21].[ReportProductNO] AS [ReportProductNO], [Project21].[LotNo] AS [LotNo], [Project21].[DateProduced] AS [DateProduced], [Project21].[ExPlant] AS [ExPlant], [Project21].[GoodsName] AS [GoodsName], [Project21].[CustomerName] AS [CustomerName], [Project21].[EmpName] AS [EmpName], [Project21].[C1] AS [C1], [Project21].[C2] AS [C2], [Project21].[C3] AS [C3], [Project21].[C4] AS [C4], [Project21].[C5] AS [C5], [Project21].[C6] AS [C6], [Project21].[C7] AS [C7] FROM ( SELECT [Project19].[ReportProductID] AS [ReportProductID], [Project19].[ReportProductNO] AS [ReportProductNO], [Project19].[LotNo] AS [LotNo], [Project19].[DateProduced] AS [DateProduced], [Project19].[ExPlant] AS [ExPlant], [Project19].[GoodsName] AS [GoodsName], [Project19].[CustomerName] AS [CustomerName], [Project19].[EmpName] AS [EmpName], [Project19].[C1] AS [C1], [Project19].[C2] AS [C2], [Project19].[C3] AS [C3], [Project19].[C4] AS [C4], [Project19].[C5] AS [C5], [Project19].[C6] AS [C6], (SELECT TOP (1) [Extent11].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent11] WHERE ([Project19].[ReportProductID] = [Extent11].[ReportProductID]) AND ('10' = [Extent11].[TestItemID])) AS [C7] FROM ( SELECT [Project18].[ReportProductID] AS [ReportProductID], [Project18].[ReportProductNO] AS [ReportProductNO], [Project18].[LotNo] AS [LotNo], [Project18].[DateProduced] AS [DateProduced], [Project18].[ExPlant] AS [ExPlant], [Project18].[GoodsName] AS [GoodsName], [Project18].[CustomerName] AS [CustomerName], [Project18].[EmpName] AS [EmpName], [Project18].[C1] AS [C1], [Project18].[C2] AS [C2], [Project18].[C3] AS [C3], [Project18].[C4] AS [C4], [Project18].[C5] AS [C5], [Project18].[C6] AS [C6] FROM ( SELECT [Project16].[ReportProductID] AS [ReportProductID], [Project16].[ReportProductNO] AS [ReportProductNO], [Project16].[LotNo] AS [LotNo], [Project16].[DateProduced] AS [DateProduced], [Project16].[ExPlant] AS [ExPlant], [Project16].[GoodsName] AS [GoodsName], [Project16].[CustomerName] AS [CustomerName], [Project16].[EmpName] AS [EmpName], [Project16].[C1] AS [C1], [Project16].[C2] AS [C2], [Project16].[C3] AS [C3], [Project16].[C4] AS [C4], [Project16].[C5] AS [C5], (SELECT TOP (1) [Extent10].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent10] WHERE ([Project16].[ReportProductID] = [Extent10].[ReportProductID]) AND ('9' = [Extent10].[TestItemID])) AS [C6] FROM ( SELECT [Project15].[ReportProductID] AS [ReportProductID], [Project15].[ReportProductNO] AS [ReportProductNO], [Project15].[LotNo] AS [LotNo], [Project15].[DateProduced] AS [DateProduced], [Project15].[ExPlant] AS [ExPlant], [Project15].[GoodsName] AS [GoodsName], [Project15].[CustomerName] AS [CustomerName], [Project15].[EmpName] AS [EmpName], [Project15].[C1] AS [C1], [Project15].[C2] AS [C2], [Project15].[C3] AS [C3], [Project15].[C4] AS [C4], [Project15].[C5] AS [C5] FROM ( SELECT [Project13].[ReportProductID] AS [ReportProductID], [Project13].[ReportProductNO] AS [ReportProductNO], [Project13].[LotNo] AS [LotNo], [Project13].[DateProduced] AS [DateProduced], [Project13].[ExPlant] AS [ExPlant], [Project13].[GoodsName] AS [GoodsName], [Project13].[CustomerName] AS [CustomerName], [Project13].[EmpName] AS [EmpName], [Project13].[C1] AS [C1], [Project13].[C2] AS [C2], [Project13].[C3] AS [C3], [Project13].[C4] AS [C4], (SELECT TOP (1) [Extent9].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent9] WHERE ([Project13].[ReportProductID] = [Extent9].[ReportProductID]) AND ('30' = [Extent9].[TestItemID])) AS [C5] FROM ( SELECT [Project12].[ReportProductID] AS [ReportProductID], [Project12].[ReportProductNO] AS [ReportProductNO], [Project12].[LotNo] AS [LotNo], [Project12].[DateProduced] AS [DateProduced], [Project12].[ExPlant] AS [ExPlant], [Project12].[GoodsName] AS [GoodsName], [Project12].[CustomerName] AS [CustomerName], [Project12].[EmpName] AS [EmpName], [Project12].[C1] AS [C1], [Project12].[C2] AS [C2], [Project12].[C3] AS [C3], [Project12].[C4] AS [C4] FROM ( SELECT [Project10].[ReportProductID] AS [ReportProductID], [Project10].[ReportProductNO] AS [ReportProductNO], [Project10].[LotNo] AS [LotNo], [Project10].[DateProduced] AS [DateProduced], [Project10].[ExPlant] AS [ExPlant], [Project10].[GoodsName] AS [GoodsName], [Project10].[CustomerName] AS [CustomerName], [Project10].[EmpName] AS [EmpName], [Project10].[C1] AS [C1], [Project10].[C2] AS [C2], [Project10].[C3] AS [C3], (SELECT TOP (1) [Extent8].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent8] WHERE ([Project10].[ReportProductID] = [Extent8].[ReportProductID]) AND ('8' = [Extent8].[TestItemID])) AS [C4] FROM ( SELECT [Project9].[ReportProductID] AS [ReportProductID], [Project9].[ReportProductNO] AS [ReportProductNO], [Project9].[LotNo] AS [LotNo], [Project9].[DateProduced] AS [DateProduced], [Project9].[ExPlant] AS [ExPlant], [Project9].[GoodsName] AS [GoodsName], [Project9].[CustomerName] AS [CustomerName], [Project9].[EmpName] AS [EmpName], [Project9].[C1] AS [C1], [Project9].[C2] AS [C2], [Project9].[C3] AS [C3] FROM ( SELECT [Project7].[ReportProductID] AS [ReportProductID], [Project7].[ReportProductNO] AS [ReportProductNO], [Project7].[LotNo] AS [LotNo], [Project7].[DateProduced] AS [DateProduced], [Project7].[ExPlant] AS [ExPlant], [Project7].[GoodsName] AS [GoodsName], [Project7].[CustomerName] AS [CustomerName], [Project7].[EmpName] AS [EmpName], [Project7].[C1] AS [C1], [Project7].[C2] AS [C2], (SELECT TOP (1) [Extent7].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent7] WHERE ([Project7].[ReportProductID] = [Extent7].[ReportProductID]) AND ('46' = [Extent7].[TestItemID])) AS [C3] FROM ( SELECT [Project6].[ReportProductID] AS [ReportProductID], [Project6].[ReportProductNO] AS [ReportProductNO], [Project6].[LotNo] AS [LotNo], [Project6].[DateProduced] AS [DateProduced], [Project6].[ExPlant] AS [ExPlant], [Project6].[GoodsName] AS [GoodsName], [Project6].[CustomerName] AS [CustomerName], [Project6].[EmpName] AS [EmpName], [Project6].[C1] AS [C1], [Project6].[C2] AS [C2] FROM ( SELECT [Project4].[ReportProductID] AS [ReportProductID], [Project4].[ReportProductNO] AS [ReportProductNO], [Project4].[LotNo] AS [LotNo], [Project4].[DateProduced] AS [DateProduced], [Project4].[ExPlant] AS [ExPlant], [Project4].[GoodsName] AS [GoodsName], [Project4].[CustomerName] AS [CustomerName], [Project4].[EmpName] AS [EmpName], [Project4].[C1] AS [C1], (SELECT TOP (1) [Extent6].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent6] WHERE ([Project4].[ReportProductID] = [Extent6].[ReportProductID]) AND ('7' = [Extent6].[TestItemID])) AS [C2] FROM ( SELECT [Project3].[ReportProductID] AS [ReportProductID], [Project3].[ReportProductNO] AS [ReportProductNO], [Project3].[LotNo] AS [LotNo], [Project3].[DateProduced] AS [DateProduced], [Project3].[ExPlant] AS [ExPlant], [Project3].[GoodsName] AS [GoodsName], [Project3].[CustomerName] AS [CustomerName], [Project3].[EmpName] AS [EmpName], [Project3].[C1] AS [C1] FROM ( SELECT [Project1].[ReportProductID] AS [ReportProductID], [Project1].[ReportProductNO] AS [ReportProductNO], [Project1].[LotNo] AS [LotNo], [Project1].[DateProduced] AS [DateProduced], [Project1].[ExPlant] AS [ExPlant], [Project1].[GoodsName] AS [GoodsName], [Project1].[CustomerName] AS [CustomerName], [Project1].[EmpName] AS [EmpName], (SELECT TOP (1) [Extent5].[TestValue] AS [TestValue] FROM [dbo].[ReportProductResults] AS [Extent5] WHERE ([Project1].[ReportProductID] = [Extent5].[ReportProductID]) AND ('1' = [Extent5].[TestItemID])) AS [C1] FROM ( SELECT [Filter1].[ReportProductID] AS [ReportProductID], [Filter1].[ReportProductNO] AS [ReportProductNO], [Filter1].[LotNo] AS [LotNo], [Filter1].[DateProduced] AS [DateProduced], [Filter1].[ExPlant] AS [ExPlant], [Filter1].[GoodsName] AS [GoodsName], [Filter1].[CustomerName] AS [CustomerName], [Extent4].[EmpName] AS [EmpName] FROM (SELECT [Extent1].[ReportProductID] AS [ReportProductID], [Extent1].[ReportProductNO] AS [ReportProductNO], [Extent1].[LotNo] AS [LotNo], [Extent1].[DateProduced] AS [DateProduced], [Extent1].[ExPlant] AS [ExPlant], [Extent1].[LoginUserID] AS [LoginUserID], [Extent2].[GoodsName] AS [GoodsName], [Extent3].[CustomerName] AS [CustomerName] FROM [dbo].[ReportProducts] AS [Extent1] INNER JOIN [dbo].[Goods] AS [Extent2] ON [Extent1].[GoodsID] = [Extent2].[GoodsID] LEFT OUTER JOIN [dbo].[Customers] AS [Extent3] ON [Extent1].[CustomerID] = [Extent3].[CustomerID] WHERE @GoodsID = [Extent1].[GoodsID] ) AS [Filter1] LEFT OUTER JOIN [dbo].[LoginUsers] AS [Extent4] ON [Filter1].[LoginUserID] = [Extent4].[LoginUserID] WHERE ([Filter1].[DateProduced] <= @EndDate) AND ([Filter1].[DateProduced] >= @StartDate) ) AS [Project1] ) AS [Project3] ) AS [Project4] ) AS [Project6] ) AS [Project7] ) AS [Project9] ) AS [Project10] ) AS [Project12] ) AS [Project13] ) AS [Project15] ) AS [Project16] ) AS [Project18] ) AS [Project19] ) AS [Project21] ) AS [Project22] ) AS [Project24] ) AS [Project25] ) AS [Project27] ) AS [Project28] ) AS [Project30] ) AS [Project31] ) AS [Project33] ) AS [Project34] ) AS [Project36] ) AS [Project37] ) AS [Project39] ) AS [Project40] ) AS [Project42] ) AS [Project43] ) AS [Project45] ) AS [Project46] ) AS [Project48] ) AS [Project49] ) AS [Project51] ) AS [Project52] ORDER BY [Project52].[DateProduced] ASC";
            
            foreach (var goods in goodsSemiList)
            {
                //this month
                SqlParameter startDateSqlParameterMonth = new SqlParameter("@StartDate", startDate);
                SqlParameter endDateSqlParameterMonth = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterMonth = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersMonth = new SqlParameter[] { startDateSqlParameterMonth, endDateSqlParameterMonth, GoodsIDSqlParameterMonth };
                //this year
                SqlParameter startDateSqlParameterYear = new SqlParameter("@StartDate", new DateTime(startDate.Year, 01, 01));
                SqlParameter endDateSqlParameterYear = new SqlParameter("@EndDate", endDate);
                SqlParameter GoodsIDSqlParameterYear = new SqlParameter("@GoodsID", goods.GoodsID);
                SqlParameter[] SqlParametersYear = new SqlParameter[] { startDateSqlParameterYear, endDateSqlParameterYear, GoodsIDSqlParameterYear };


                ShippingMonthReportModel reportModel = new ShippingMonthReportModel();
                reportModel.dataTableThisMonth = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersMonth);
                reportModel.dataTableThisYear = LimsDbHelper.SqlQueryForDataTatable(db.Database, sql, SqlParametersYear);

                reportModel.viewStartRowIndex = startRowIndex;
                reportModel.viewEndRowIndex = startRowIndex + 14;     //16 表格    28曲线图  2空行

                reportModel.monthDataStartRowIndex = startRowIndexMonth;
                reportModel.monthDataEndRowIndex = startRowIndexMonth + reportModel.dataTableThisMonth.Rows.Count + 8;

                reportModel.yearDataStartRowIndex = startRowIndexYear;
                reportModel.yearDataEndRowIndex = startRowIndexYear + reportModel.dataTableThisYear.Rows.Count + 8;

                reportModel.goodsName = goods.GoodsName;
                //reportModel.standardSemiList = db.StandardCustomers.Where(m => m.GoodsID == goods.GoodsID ).ToList();

                if (reportModel.dataTableThisMonth.Rows.Count > 0)
                {
                    DoData.Add(reportModel);
                    startRowIndex = reportModel.viewEndRowIndex + 2;
                    startRowIndexMonth = reportModel.monthDataEndRowIndex + 2;
                    startRowIndexYear = reportModel.yearDataEndRowIndex + 2;
                }
            }

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];

            worksheetShippingView.Columns[2].Width = 600;


            for (int i = 0; i < DoData.Count; i++)
            {
                worksheetShippingThisMonth.Import(DoData[i].dataTableThisMonth, true, DoData[i].monthDataStartRowIndex, 1);
                worksheetShippingThisYear.Import(DoData[i].dataTableThisYear, true, DoData[i].yearDataStartRowIndex, 1);

                worksheetShippingView[DoData[i].viewStartRowIndex + 5, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();

                worksheetShippingView[DoData[i].viewStartRowIndex + 11, 2].Value = new DateTime(startDate.Year, 01, 01).ToShortDateString() + "--" + endDate.ToShortDateString();


                //写Month标准
                //worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 7, 1].Value = "LSL";
                //worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 6, 1].Value = "USL";
                //worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 7, 1].Value = "LSL";
                //worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 6, 1].Value = "USL";

                //WriteShippingDataStanard(DoData[i], 8, DoData[i].standardCustomerList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 9, DoData[i].standardCustomerList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 14, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 15, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 16, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 17, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 18, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_LT_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 19, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_PD_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 20, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_PH_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 21, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Tint_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 22, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_CDBP_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 23, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_N2SA_ID).FirstOrDefault());
                //WriteShippingDataStanard(DoData[i], 24, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Ash_ID).FirstOrDefault());



                //WriteShippingViewStandard(DoData[i], 4, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IA_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 5, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_DBP_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 6, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHavg_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 7, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHhigh_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 8, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_IPHlow_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 9, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Fines_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 10, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_HL_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 11, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue35_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 12, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue100_ID).FirstOrDefault());
                //WriteShippingViewStandard(DoData[i], 13, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_SieveResidue325_ID).FirstOrDefault());

                worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 5, 1].Value = "Count";
                worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 1, 1].Value = "Max.";
                // worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 0, 1].Value = "Cpk";

                worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 5, 1].Value = "Count";
                worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, 1].Value = "Avg.";
                worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 3, 1].Value = "Std.";
                worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 2, 1].Value = "Min.";
                worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 1, 1].Value = "Max.";
                // worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 0, 1].Value = "Cpk";



                for (int c = 8; c < 25; c++)
                {
                    Cell cellLT = worksheetShippingThisMonth[DoData[i].monthDataStartRowIndex + 1, c];
                    Cell cellRB = worksheetShippingThisMonth[DoData[i].monthDataStartRowIndex + 1 + DoData[i].dataTableThisMonth.Rows.Count - 1, c];
                    //count Month  COUNTA
                    string formulaCount = "COUNTA(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")";
                    worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 5, c].ArrayFormula = formulaCount;
                    //avg Month   
                    string formulaAvg = "=IFERROR(AVERAGEIF(" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ",\">=0\"," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "),\"\")";
                    worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, c].ArrayFormula = formulaAvg;
                    Cell avg = worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //max Month     =MAX(IF((E7:E66>0),E7:E66))
                    string formulaMax = "=MAX(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 1, c].ArrayFormula = formulaMax;
                    Cell MAX = worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, c];
                    //Min Month   =MIN(IF((E7:E66>0),E7:E66))
                    string formulaMin = "=MIN(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + "))";
                    worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 2, c].ArrayFormula = formulaMin;
                    //std Month  =IFERROR(STDEV(IF((E7:E66>0),E7:E66)),"")
                    string formulaSTDEV = "=IFERROR(STDEV(IF((" + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ">0)," + cellLT.GetReferenceA1() + ":" + cellRB.GetReferenceA1() + ")),\"\")";
                    worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEV;
                    //cpk   Month
                    string cellLSL =  worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSL =  worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVG =  worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStd =  worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                   // string formulaCPK = "=IFERROR(IF(AND(" + cellUSL + "=\"\"," + cellLSL + "=\"\"),\"\",MIN((" + cellUSL + "-" + cellAVG + ")/3/" + cellStd + ",(" + cellAVG + "-" + cellLSL + ")/3/" + cellStd + ")),\"\")";
                   // worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 0, c].ArrayFormula = formulaCPK;



                    string countMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKMonthFormula = "=" + "'" + cellLT.Worksheet.Name + "'" + "!" + worksheetShippingThisMonth[DoData[i].monthDataEndRowIndex - 0, c].GetReferenceA1();


                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 4, c - 4, countMonthFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 5, c - 4, avgMonthFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 6, c - 4, STDEVMonthFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 7, c - 4, MinMonthFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 8, c - 4, MaxMonthFormula);
                   //  ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 9, c - 4, CPKMonthFormula);



                    /////////////////////////////////////////////统计this Year
                    Cell cellLTYaer = worksheetShippingThisYear[DoData[i].yearDataStartRowIndex + 1, c];
                    Cell cellRBYaer = worksheetShippingThisYear[DoData[i].yearDataStartRowIndex + 1 + DoData[i].dataTableThisYear.Rows.Count - 1, c];
                    //count  COUNTA
                    string formulaCountYear = "COUNTA(" + cellLTYaer.GetReferenceA1() + ":"  + cellRBYaer.GetReferenceA1() + ")";
                    worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 5, c].ArrayFormula = formulaCountYear;
                    //avg Month
                    string formulaAvgYear = @"=IFERROR(AVERAGEIF(" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ",\">=0\"," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "),\"\")";
                    worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, c].ArrayFormula = formulaAvgYear;
                    Cell avgYear = worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //max Month
                    string formulaMaxYear = "=MAX(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 1, c].ArrayFormula = formulaMaxYear;
                    Cell MAXYear = worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, c];
                    //Min Month
                    string formulaMinYear = "=MIN(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + "))";
                    worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 2, c].ArrayFormula = formulaMinYear;
                    //std Month
                    string formulaSTDEVYear = "=IFERROR(STDEV(IF((" + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ">0)," + cellLTYaer.GetReferenceA1() + ":" + cellRBYaer.GetReferenceA1() + ")),\"\")";
                    worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 3, c].ArrayFormula = formulaSTDEVYear;
                    //cpk   Month
                    string cellLSLYear =  worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 7, c].GetReferenceA1();
                    string cellUSLYear =  worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 6, c].GetReferenceA1();
                    string cellAVGYear =  worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string cellStdYear =  worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    // =IFERROR(IF(AND(E109="",E110=""),"",MIN((E109-E118)/3/E119,(E118-E110)/3/E119)),"")      E109 USL    E110 LSL   E118 Avg.       E119 Std.
                   // string formulaCPKYear = "=IFERROR(IF(AND(" + cellUSL + "=\"\"," + cellLSL + "=\"\"),\"\",MIN((" + cellUSL + "-" + cellAVG + ")/3/" + cellStd + ",(" + cellAVG + "-" + cellLSL + ")/3/" + cellStd + ")),\"\")";
                   // worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 0, c].ArrayFormula = formulaCPK;



                    string countYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 5, c].GetReferenceA1();
                    string avgYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 4, c].GetReferenceA1();
                    string STDEVYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 3, c].GetReferenceA1();
                    string MinYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 2, c].GetReferenceA1();
                    string MaxYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 1, c].GetReferenceA1();
                    string CPKYearFormula = "=" + "'" + cellLTYaer.Worksheet.Name + "'" + "!" + worksheetShippingThisYear[DoData[i].yearDataEndRowIndex - 0, c].GetReferenceA1();

                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 10, c - 4, countYearFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 11, c - 4, avgYearFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 12, c - 4, STDEVYearFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 13, c - 4, MinYearFormula);
                    ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 14, c - 4, MaxYearFormula);
                   // ShippingWriteDataDetail(DoData[i].viewStartRowIndex + 15, c - 4, CPKYearFormula);


                }
                // WriteShippingStanardColumn(DoData[i], 26, DoData[i].standardSemiList.Where(m => m.TestItemID == CommonData.TestItem_Tint_ID).FirstOrDefault(), "Tint");
                ShippingWriteTitel(DoData[i], i);
                ShippingDecorate(DoData[i], startDate, endDate);


            }

        }
        private void WriteShippingDataStanard(DoMonthReportModel reportModel, int column, StandardCustomer standard)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];


            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetShippingThisMonth[reportModel.monthDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                    worksheetShippingThisYear[reportModel.yearDataEndRowIndex - 7, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetShippingThisMonth[reportModel.monthDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                    worksheetShippingThisYear[reportModel.yearDataEndRowIndex - 7 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void WriteShippingViewStandard(DoMonthReportModel reportModel, int column, StandardCustomer standard)
        {

            //IWorkbook workbook = spreadsheetControl1.Document;
            //Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            //Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            //Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];

            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDOView = workbook.Worksheets["4)Shipping"];
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2, column].Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    worksheetDOView[reportModel.viewStartRowIndex + 2 + 1, column].Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }

        private void WriteShippingDataColumnStanard(ShippingMonthReportModel reportModel, int column, StandardSemi standard, string columnName)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];

            worksheetShippingThisMonth[reportModel.monthDataStartRowIndex, column].Value = columnName + "_LSL";
            worksheetShippingThisMonth[reportModel.monthDataStartRowIndex, column + 1].Value = columnName + "_USL";
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    Range rangeIA_LSL = worksheetShippingThisMonth.Range.FromLTRB(column, reportModel.monthDataStartRowIndex + 1, column, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    Range rangeIA_LSL = worksheetShippingThisMonth.Range.FromLTRB(column + 1, reportModel.monthDataStartRowIndex + 1, column + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        private void ShippingWriteDataDetail(int row, int column, string formula)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["4)Shipping"];
            worksheetDoView[row, column].Formula = formula;
        }

        private void ShippingWriteTitel(ShippingMonthReportModel semiReport, int NO)
        {
            //IWorkbook workbook = spreadsheetControl1.Document;
            //Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            //Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            //Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];


            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetShipping = workbook.Worksheets["4)Shipping"];

            // 第一行  Unit    Grade   
            worksheetShipping[semiReport.viewStartRowIndex, 0].Value = "Unit";
            worksheetShipping[semiReport.viewStartRowIndex, 1].Value = "Grade";
            worksheetShipping[semiReport.viewStartRowIndex, 2].Value = "Month";
            worksheetShipping[semiReport.viewStartRowIndex, 3].Value = "Category";
            worksheetShipping[semiReport.viewStartRowIndex, 4].Value = "IA(g/kg)";
            worksheetShipping[semiReport.viewStartRowIndex, 5].Value = "DBP(ml/100g)";
            worksheetShipping[semiReport.viewStartRowIndex, 6].Value = "IPH(gf)";
            worksheetShipping[semiReport.viewStartRowIndex, 9].Value = "Fines(%)";
            worksheetShipping[semiReport.viewStartRowIndex, 10].Value = "HL(%)";
            worksheetShipping[semiReport.viewStartRowIndex, 11].Value = "Sieve Residue(ppm)";

            worksheetShipping[semiReport.viewStartRowIndex, 14].Value = "LT(%)";
            worksheetShipping[semiReport.viewStartRowIndex, 15].Value = "PD(kg/m³)";
            worksheetShipping[semiReport.viewStartRowIndex, 16].Value = "PH";
            worksheetShipping[semiReport.viewStartRowIndex, 17].Value = "Tint(%)";
            worksheetShipping[semiReport.viewStartRowIndex, 18].Value = "CDBP(ml/100g)";
            worksheetShipping[semiReport.viewStartRowIndex, 19].Value = "N2SA(㎡/g)";
            worksheetShipping[semiReport.viewStartRowIndex, 20].Value = "Ash(%)";
            //第二行
            worksheetShipping[semiReport.viewStartRowIndex + 1, 6].Value = "AVG";
            worksheetShipping[semiReport.viewStartRowIndex + 1, 7].Value = "High";
            worksheetShipping[semiReport.viewStartRowIndex + 1, 8].Value = "Low";
            worksheetShipping[semiReport.viewStartRowIndex + 1, 11].Value = "#35";
            worksheetShipping[semiReport.viewStartRowIndex + 1, 12].Value = "#100";
            worksheetShipping[semiReport.viewStartRowIndex + 1, 13].Value = "#325";
            //合并单元格  横向 IPH     Sieve
            Range rangeIPH = worksheetShipping.Range.FromLTRB(6, semiReport.viewStartRowIndex, 8, semiReport.viewStartRowIndex);
            worksheetShipping.MergeCells(rangeIPH);
            Range rangeSieve = worksheetShipping.Range.FromLTRB(11, semiReport.viewStartRowIndex, 13, semiReport.viewStartRowIndex);
            worksheetShipping.MergeCells(rangeSieve);
            //合并单元格 zongxiang
            int[] intArray = new int[] { 0, 1, 2, 3, 4, 5, 9, 10 };
            foreach (int i in intArray)
            {
                Range rangeUnit = worksheetShipping.Range.FromLTRB(i, semiReport.viewStartRowIndex, i, semiReport.viewStartRowIndex + 1);
                worksheetShipping.MergeCells(rangeUnit);
            }
            //标题第一行加高
            RowCollection rows = worksheetShipping.Rows;
            Row row_byIndex = rows[semiReport.viewStartRowIndex];
            row_byIndex.RowHeight = 140;
            //字体加粗  居中

            //合并Unit 下方单元格   Grade下方单元格
            Range rangeUnitDetail = worksheetShipping.Range.FromLTRB(0, semiReport.viewStartRowIndex + 2, 0, semiReport.viewStartRowIndex + 15);
            worksheetShipping[semiReport.viewStartRowIndex + 2, 0].Value = NO + 1;
            worksheetShipping[semiReport.viewStartRowIndex + 2, 0].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetShipping[semiReport.viewStartRowIndex + 2, 0].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            Range rangeGradeDetail = worksheetShipping.Range.FromLTRB(1, semiReport.viewStartRowIndex + 2, 1, semiReport.viewStartRowIndex + 15);
            worksheetShipping[semiReport.viewStartRowIndex + 2, 1].Value = semiReport.goodsName;
            worksheetShipping[semiReport.viewStartRowIndex + 2, 1].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetShipping[semiReport.viewStartRowIndex + 2, 1].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

            worksheetShipping.MergeCells(rangeUnitDetail);
            worksheetShipping.MergeCells(rangeGradeDetail);
            //合并month下方 spec‘单元格
            Range rangeSpec = worksheetShipping.Range.FromLTRB(2, semiReport.viewStartRowIndex + 2, 2, semiReport.viewStartRowIndex + 3);
            worksheetShipping.MergeCells(rangeSpec);
            worksheetShipping[semiReport.viewStartRowIndex + 2, 2].Value = "spec'";
            worksheetShipping[semiReport.viewStartRowIndex + 2, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetShipping[semiReport.viewStartRowIndex + 2, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 Month‘单元格
            Range rangeMonthCurrent = worksheetShipping.Range.FromLTRB(2, semiReport.viewStartRowIndex + 4, 2, semiReport.viewStartRowIndex + 9);
            worksheetShipping.MergeCells(rangeMonthCurrent);
            // worksheetDO[semiReport.viewStartRowIndex + 4, 2].Value = startDate.ToShortDateString() + "--" + endDate.ToShortDateString();       //当前月份
            worksheetShipping[semiReport.viewStartRowIndex + 4, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetShipping[semiReport.viewStartRowIndex + 4, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //合并month下方 之前月份 ‘单元格
            Range rangeMonthBefore = worksheetShipping.Range.FromLTRB(2, semiReport.viewStartRowIndex + 10, 2, semiReport.viewStartRowIndex + 15);
            worksheetShipping.MergeCells(rangeMonthBefore);

            worksheetShipping[semiReport.viewStartRowIndex + 10, 2].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            worksheetShipping[semiReport.viewStartRowIndex + 10, 2].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            //Category
            worksheetShipping[semiReport.viewStartRowIndex + 2, 3].Value = "LSL";
            worksheetShipping[semiReport.viewStartRowIndex + 3, 3].Value = "USL";
            worksheetShipping[semiReport.viewStartRowIndex + 4, 3].Value = "Count";
            worksheetShipping[semiReport.viewStartRowIndex + 5, 3].Value = "Avg.";
            worksheetShipping[semiReport.viewStartRowIndex + 6, 3].Value = "Std.";
            worksheetShipping[semiReport.viewStartRowIndex + 7, 3].Value = "Min.";
            worksheetShipping[semiReport.viewStartRowIndex + 8, 3].Value = "Max.";
            worksheetShipping[semiReport.viewStartRowIndex + 9, 3].Value = "Cpk";

            worksheetShipping[semiReport.viewStartRowIndex + 10, 3].Value = "Count";
            worksheetShipping[semiReport.viewStartRowIndex + 11, 3].Value = "Avg.";
            worksheetShipping[semiReport.viewStartRowIndex + 12, 3].Value = "Std.";
            worksheetShipping[semiReport.viewStartRowIndex + 13, 3].Value = "Min.";
            worksheetShipping[semiReport.viewStartRowIndex + 14, 3].Value = "Max.";
            worksheetShipping[semiReport.viewStartRowIndex + 15, 3].Value = "Cpk";
        }

        private void ShippingDecorate(ShippingMonthReportModel reportModel, DateTime startDate, DateTime endDate)
        {

            //IWorkbook workbook = spreadsheetControl1.Document;
            //Worksheet worksheetShippingThisMonth = workbook.Worksheets["Shipping_ThisMonthData"];
            //Worksheet worksheetShippingThisYear = workbook.Worksheets["Shipping_ThisYearData"];
            //Worksheet worksheetShippingView = workbook.Worksheets["4)Shipping"];


            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetDoView = workbook.Worksheets["4)Shipping"];
            //加边框
            Range range = worksheetDoView.Range.FromLTRB(0, reportModel.viewStartRowIndex, 20, reportModel.viewStartRowIndex + 15);
            range.SetInsideBorders(Color.Black, BorderLineStyle.Dashed);
            range.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);
            range.Font.Bold = true;
            Formatting rangeFormatting1 = range.BeginUpdateFormatting();
            rangeFormatting1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            range.EndUpdateFormatting(rangeFormatting1);
            //一年的数据加背景颜色
            Range rangeYear = worksheetDoView.Range.FromLTRB(2, reportModel.viewStartRowIndex + 10, 20, reportModel.viewStartRowIndex + 15);

            Formatting rangeFormatting2 = rangeYear.BeginUpdateFormatting();
            rangeFormatting2.Fill.BackgroundColor = Color.FromArgb(204, 255, 204);
            rangeFormatting2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
            rangeFormatting2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
            rangeYear.EndUpdateFormatting(rangeFormatting2);


        }

        private void ShippingCreateChart(ShippingMonthReportModel reportModel, Cell TopLeftCell, Cell BottomRightCell)
        {
            //  IA  DBP 
            //FInes SR#325
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetCompView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetComp_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetComp_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];

            Chart chartIA = worksheetCompView.Charts.Add(ChartType.ScatterLineMarkers);
            chartIA.TopLeftCell = TopLeftCell;
            chartIA.BottomRightCell = BottomRightCell;
            //创建IA的 曲线
            Range nameIARane = worksheetComp_ThisMonthData.Range.FromLTRB(21, reportModel.monthDataStartRowIndex, 21, reportModel.monthDataStartRowIndex);
            Range valueRange = worksheetComp_ThisMonthData.Range.FromLTRB(21, reportModel.monthDataStartRowIndex + 1, 21, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            Range agumentRage = worksheetComp_ThisMonthData.Range.FromLTRB(5, reportModel.monthDataStartRowIndex + 1, 5, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameIARane, agumentRage, valueRange);

            //下限
            Range nameLSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26, reportModel.monthDataStartRowIndex, 26, reportModel.monthDataStartRowIndex);
            Range valueLSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26, reportModel.monthDataStartRowIndex + 1, 26, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameLSLRange, agumentRage, valueLSLRange);
            //上线
            Range nameUSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26 + 1, reportModel.monthDataStartRowIndex, 26 + 1, reportModel.monthDataStartRowIndex);
            Range valueUSLRange = worksheetComp_ThisMonthData.Range.FromLTRB(26 + 1, reportModel.monthDataStartRowIndex + 1, 26 + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
            chartIA.Series.Add(nameUSLRange, agumentRage, valueUSLRange);



            chartIA.Legend.Position = LegendPosition.Bottom;
            chartIA.Title.Visible = true;
            chartIA.Title.SetValue(reportModel.goodsName);








        }

        private void WriteShippingStanardColumn(ShippingMonthReportModel reportModel, int column, StandardSemi standard, string columnName)
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheetCompView = workbook.Worksheets["2)Comp"];
            Worksheet worksheetComp_ThisMonthData = workbook.Worksheets["Comp_ThisMonthData"];
            Worksheet worksheetComp_ThisYearData = workbook.Worksheets["Comp_ThisYearData"];

            worksheetComp_ThisMonthData[reportModel.monthDataStartRowIndex, column].Value = columnName + "_LSL";
            worksheetComp_ThisMonthData[reportModel.monthDataStartRowIndex, column + 1].Value = columnName + "_USL";
            if (standard != null)
            {
                if (!String.IsNullOrEmpty(standard.MinValue))
                {
                    Range rangeIA_LSL = worksheetComp_ThisMonthData.Range.FromLTRB(column, reportModel.monthDataStartRowIndex + 1, column, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MinValue);
                }
                if (!String.IsNullOrEmpty(standard.MaxValue))
                {
                    Range rangeIA_LSL = worksheetComp_ThisMonthData.Range.FromLTRB(column + 1, reportModel.monthDataStartRowIndex + 1, column + 1, reportModel.monthDataStartRowIndex + reportModel.dataTableThisMonth.Rows.Count);
                    rangeIA_LSL.Value = Convert.ToDouble(standard.MaxValue);
                }
            }
        }
        #endregion






    }
}
